P4409 [ZJOI2006] emperor's troubles

Title Description

After years of killing, Qin finally unified China. In order to resist foreign aggression, he was ready to resettlement n generals in the land border. Unfortunately this fledgling n generals, began to show up their wild ambition. They refused to report on his work, refused to accept the emperor's decree.

Qin ready secretly executed these rude frontier generals.

However, to prevent mutiny, he decided to grant some of these generals medal, won the strategic time for yourself. The generals heard that they are very happy about to be awarded the medal, they have expressed gratitude letter. The i-th general requirements are different colors ai gold medal. But these generals are arrogant, if two adjacent generals have the same color medal they will think they do not respect the emperor, would immediately rebel (i number of generals and generals adjacent numbered i + 1; because they may similarly stationed as a circular border, the general number 1 and the number n are also adjacent).

The emperor had to meet the requirements of each of the generals, but their domineering feel very angry. So the emperor decided to cast as little as possible to meet the requirements of the type of medal of these arrogant person. Will he at least Medal how many colors you want to cast?

Input Format

The first line has an integer n (1 <= n <= 20000).

The next n lines each an integer ai, represents how many medals obtained i-th general requirements. (1 <= ai <= 100000)

Output Format

Output An integer that is at least how many medals needs.

Sample input and output

Input # 1
4
2 2 1 1
Output # 1
4

Thinking

In line to the giant guy

Code

#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

const int N=20010;

int ans;
int n,m,a[N];

int main () {
	scanf("%d",&n);
	for(int i=1; i<=n; i++)
		scanf("%d",&a[i]);
	if(n==1) {
		printf("%d\n",&n);
		return 0;
	}
	ans=a[1]+a[n];
	for(int i=1; i<n; ++i)
		if(a[i]+a[i+1]>ans)
			ans=a[i]+a[i+1];
	for(int i=1; i<=n; ++i)
		m+=a[i];
	double mm=m,nn=n,tmp;
	tmp=ceil(mm/((int)(nn/2)));
	if((int)tmp>years) 
		years = (int) tmp;
	printf ( "% d \ n", year);
	return 0;
}

 

Guess you like

Origin www.cnblogs.com/mysh/p/11441073.html