Topic description
Background
As we all know, Pampas is the place where the eagle soars, where there are many eagles, @ Pampas Eagle in order to display their own unique feathers dyed, which caused him trouble
Topic
In Pampas, they dominate the central part of the grassland, where the eagle's territory surrounds the cattle, and each hawk has its own territory. At the @ Pampas Eagle will be dyed feathers, the other eagles have followed, but also want to dye their feathers into colorful. But the problem with it is that the next two Eagles (1 and 2 adjacent, 1 and N are also adjacent) will have a life-and-death air battle with each other if they find feathers with the same color as themselves. In order to avoid this situation, we must think of a way to do it. Because the @ Pampas Eagle is the first eagle to dye feathers, he was assigned by the Eagle to buy paint (at his own expense t_t), of course, to buy paint is to spend money. @ Pampas Eagle wants to buy less paint as much as possible. He found that because of different eagle's preferences, they want to dye the number of colors are not the same, some eagles like to paint their feathers more color, some less. By statistics, the first eagle wants to paint AI colors on himself. Your task now is to maintain peace in the world. Find the least color type so that each adjacent eagle has the same feather color. Input format
First line N (1<=n<=20000)
The second line starts with a number of each line AI (1<=ai<=100000) represents the first eagle to be painted AI color output format
A number, that is, the least satisfying condition of the color type sample input
4 2 2 1 1 Sample output
4
Three-dimensional state image
To refer to the Barty:
Mathematical Methods
Because the adjacent cannot have duplicate color, so the number of colors is at least the number of adjacent two feathers sum
Also consider a total of M-root feathers, the same color feathers have (n div 2) root, so the color has at least m div (n div 2) Species {Note is the upper rounding}.
Finish.
#include <stdio.h> #include <math.h> int ans; int a[20001],m,n,i,j int main () {scanf ("%d", &n); for (i= 1;i<=n;++i) scanf ("%d", &a[i]); for (I=1;i<n;++i) if (A[i]+a[i+1]>ans) ans=a[i]+a[i+1]; for (I=1;i<=n;++i) m+=a[i]; Double Mm=m,nn=n,tem; Tem=ceil (mm/(int) (NN/2)); if ((int) tem>ans) ans= (int) tem; printf ("%d/n", ans); return 0; }