首页 > 其他 > 详细

HDU 1205 鸽巢原理

时间:2017-06-16 21:51:06      阅读:299      评论:0      收藏:0      [点我收藏+]

技术分享

 

技术分享
#include <bits/stdc++.h>

using namespace std;

long long abs_(long long a,long long b) {
    if(a>=b)
        return a-b;
    else return b-a;
}

int main()
{
    int t;
    scanf("%d",&t);
    while(t--) {
        long long maxx = -1;
        long long sum = 0;

        int n;
        scanf("%d",&n);
        long long a;
        for(int i=0;i<n;i++) {
            scanf("%lld",&a);
            maxx = max(a,maxx);
            sum+=a;
        }

        long long orther = sum - maxx+1;

        if(orther>=maxx)
            puts("Yes");
        else puts("No");

    }
    return 0;
}
View Code

 

分析:

考虑最多的元素,那么其他种类的元素,完全可以放到最多的元素的中间,不用担心他们会不会相邻;

HDU 1205 鸽巢原理

原文:http://www.cnblogs.com/TreeDream/p/7029268.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!