hdu 1205 吃糖果 输入挂+抽屉原理
2015-08-24 11:30
393 查看
有最多数量的某种糖果数量为maxn,接下来问题转化成能否将在maxn个相同的糖果序列中间差入一些其他糖果,将相同的糖果分开。根据抽屉原理,最少需要maxn-1个糖果。
#include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> #include <vector> #include <queue> #include <stack> #include <set> #include <map> #include <string> #include <math.h> #include <stdlib.h> #include <time.h> using namespace std; typedef long long ll; inline int read() { char ch=getchar();int x=0,f=1; while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();} while(ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=getchar();} return x*f; } int main() { int _,t,n,i,maxn; ll sum; scanf("%d",&_); while(_--) { scanf("%d",&n); sum=maxn=0; for(i=0;i<n;i++) { t=read(); maxn=max(t,maxn); sum+=t; } if(sum-maxn+1>=maxn) printf("Yes\n"); else printf("No\n"); } return 0; }
相关文章推荐
- window.name实现的跨域数据传输
- JavaScript跨域总结与解决办法
- 在C++代码中调用L脚本语言
- HDU 4667 Building Fence(求凸包的周长)
- TOMCAT注册成系统服务
- BSS段、数据段、代码段、堆与栈
- [C++]Excel Sheet Column Title
- 一篇文章为你解读大数据的现在和未来
- LeetCode 22:Generate Parentheses的递归,回溯两种解法
- 你应该要掌握的7种回归分析方法
- DBMS_UTILITY.EXEC_DDL_STATEMENT提示无权限
- 慢慢说CSS第二天
- Unknown Class **** in Interface Builder file
- STM32的DAC
- [LeedCode OJ]#9 Palindrome Number
- CocoaPods的简单使用
- ios把资源文件数据库拷贝到沙盒中
- 运维工单--消息队列发送邮件
- Java笔记——equals和==的区别
- se JEE 3.6 (或以上版本)新建 Dynamic web Project,直接单击 finish按钮 后 WEB-INF 下没有web.xml文件?