1. 程式人生 > >HDU 5835 Danganronpa 【規律+貪心】

HDU 5835 Danganronpa 【規律+貪心】

integer rep bsp first quotes ++ ron his als

Problem Description

Chisa Yukizome works as a teacher in the school. She prepares many gifts, which consist of n kinds with a[i] quantities of each kind, for her students and wants to hold a class meeting. Because of the busy work, she gives her gifts to the monitor, Chiaki Nanami. Due to the strange design of the school, the students‘ desks are in a row. Chiaki Nanami wants to arrange gifts like this:

1. Each table will be prepared for a mysterious gift and an ordinary gift.

2. In order to reflect the Chisa Yukizome‘s generosity, the kinds of the ordinary gift on the adjacent table must be different.

3. There are no limits for the mysterious gift.

4. The gift must be placed continuously.

She wants to know how many students can get gifts in accordance with her idea at most (Suppose the number of students are infinite). As the most important people of her, you are easy to solve it, aren‘t you?

Input

The first line of input contains an integer T(T10) indicating the number of test cases.

Each case contains one integer n. The next line contains n (1n10) numbers: a1,a2,...,an, (1ai100000).

Output

For each test case, output one line containing “Case #x: y” (without quotes) , where x is the test case number (starting from 1) and y is the answer of Chiaki Nanami‘s question.

Sample Input

1 2 3 2

Sample Output

Case #1: 2

題目大意:

題意:有n種禮物,每個有ai個,現在開始給每個人發禮物,每人一個普通禮物和神秘禮物,

相鄰兩人的普通禮物必須不同,每個禮物都可以作為神秘禮物/普通禮物,問最多可以發給多少人。

大致思路:

先考慮看起來較為一般的情況:

隨便列幾組數據,發現結果都是sum/2

仔細想想也就知道最大的人數不會超過sum/2

然後考慮比較不一般的情況:

比如:1 1000這樣

那麽就可以先把個數最多的平鋪在一條線上,讓剩下的取插空,這樣就能取最多的人數了。

然後把這個人數和sum/2取一個min,就是答案

代碼:

 1
#include<bits/stdc++.h> 2 using namespace std; 3 int main() 4 { 5 ios::sync_with_stdio(false); 6 int t,cnt=1,sum,maxx; 7 int n,a[11]; 8 cin>>t; 9 for(;cnt<=t;++cnt){ 10 sum=0; 11 maxx=0; 12 cin>>n; 13 for(int i=0;i<n;++i){ 14 cin>>a[i]; 15 sum+=a[i]; 16 maxx=max(maxx,a[i]); 17 } 18 cout<<"Case #"<<cnt<<": "<<sum/2<<endl; 19 } 20 return 0; 21 }

HDU 5835 Danganronpa 【規律+貪心】