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?
Each case contains one integer n. The next line contains n (1≤n≤10) numbers: a1,a2,...,an, (1≤ai≤100000).
Sample Input Sample Output
Case #:
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5835
****************************************************
题意:有T组测试实例,每组实例有n种类型的礼物,第i种类型的礼物共有a[i]个,相邻同学的礼物不能相同,问有多少个同学能拿到符合要求的礼物。
分析:从这道题里我学到了勇于尝试的重要性%>_<%~ 脑洞尽管开,试一试不会亏呀
这道题里并没有要求童鞋们要挨着坐,所以嘞,随便坐喽,这说明了神马,这就说明了这是一道水题%>_<%~
只需要判断一人俩礼物能分几个人的问题。。。。
那些还在研究怎么坐得到的结果最多又怎么实现的童鞋们~~~你们都被出题的人给坑坏了
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <stack>
#include <map>
#include <vector>
using namespace std; #define N 12000
#define INF 0x3f3f3f3f int a[N]; int main()
{
int T,n,i,sum,k=; scanf("%d", &T); while(T--)
{
sum=;
scanf("%d", &n); for(i=;i<n;i++)
{
scanf("%d", &a[i]);
sum+=a[i];
} printf("Case #%d: ",k++);
if(sum==)
printf("1\n");
else
printf("%d\n", sum/);
}
return ;
}
附上一个让不明白的人更明白的代码:
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <math.h> using namespace std; #define met(a, b) memset(a, b, sizeof(a))
#define N 53
#define INF 0x3f3f3f3f
#define PI 4*atan(1)
const int MOD = ; typedef long long LL; int a[N]; int main()
{
int T, t = , n, sum;
scanf("%d", &T);
while(T--)
{
sum = ;
scanf("%d", &n); for(int i=; i<=n; i++)
{
scanf("%d", &a[i]);
sum += a[i];
} sort(a+, a+n+); int half = sum/; int s = sum-a[n]; if(*s+ < half)
printf("Case #%d: %d\n", t++, *s+);
else
printf("Case #%d: %d\n", t++, half);
}
return ;
}