hdu 1205 鸽巢原理
2015-01-30 22:13
330 查看
运用鸽巢原理,假设最多的糖果有Max个,那么必须要有max-1个其他种类的糖果才能吃完,如果其他种类的糖果多于max-1个,那么至少要有一个种糖果存在max+1个,才会出现当前状态无解,而这种状况下又与最多糖果数为max矛盾,所以要满足有解的充要条件是max-1 <= sum - max
#include <iostream> #include <cstdio> #include <cstdlib> #include <algorithm> #include <cstring> using namespace std; int main ( ) { int t,n; long long maxn , x , sum; scanf ( "%d" , &t ); while ( t-- ) { maxn =0; sum = 0; scanf ( "%d" , &n ); while ( n -- ) { scanf ( "%lld" , &x ); maxn = max ( maxn , x ); sum += x; } if ( sum - maxn + 1 >= maxn ) puts ( "Yes"); else puts ( "No" ); } }
相关文章推荐
- [ACM] hdu 1205 吃糖果(鸽巢原理)
- hdu 1205 吃糖果(鸽巢原理)
- HDU 1205 吃糖果(组合数学鸽巢原理)
- [ACM] hdu 1205 吃糖果(鸽巢原理)
- hdu 1205 有意思的小题 2种解法 鸽巢原理
- 吃糖果 hdu 1205 数论中思维问题 鸽巢原理
- HDU1205 鸽巢原理/找规律
- HDU 1205.吃糖果【鸽巢原理】【8月1】
- 鸽巢原理:hdu 1205 吃糖果+poj 2356 Find a multiple+poj 3370 Halloween treats
- [HDU 1205] 吃糖果 (鸽巢原理)
- HDU 1205(鸽巢原理)
- HDU——1205吃糖果(鸽巢原理)
- HDU 1205 鸽巢原理
- hdu 1205 有意思的小题 2种解法 鸽巢原理
- [ACM] hdu 1205 吃糖果(鸽巢原理)
- hdu 1205 吃糖果(鸽巢原理)
- HDU 2356 Find a multiple(鸽巢原理)
- HDU 1205吃糖果(抽屉原理还能这么用)
- HDU 1205 吃糖果 简单题
- Hdu 1029 Ignatius and the Princess IV (鸽巢原理)