zoukankan      html  css  js  c++  java
  • 吃糖果hdu2502

    HOHO,终于从Speakless手上赢走了所有的糖果,是Gardon吃糖果时有个特殊的癖好,就是不喜欢将一样的糖果放在一起吃,喜欢先吃一种,下一次吃另一种,这样;可是Gardon不知道是否存在一种吃糖果的顺序使得他能把所有糖果都吃完?请你写个程序帮忙计算一下。 

    Input第一行有一个整数T,接下来T组数据,每组数据占2行,第一行是一个整数N(0<N<=1000000),第二行是N个数,表示N种糖果的数目Mi(0<Mi<=1000000)。 
    Output对于每组数据,输出一行,包含一个"Yes"或者"No"。 
    Sample Input

    2
    3
    4 1 1
    5
    5 4 3 2 1

    Sample Output

    No
    Yes
    
    
            
     
    Please use function scanf

    Hint

    Hint
            wa了三次,,判断的时候忘记减一,QAQ!
     1 #include <iostream>
     2 using namespace std;
     3 #include<string.h>
     4 #include<set>
     5 #include<stdio.h>
     6 #include<math.h>
     7 #include<queue>
     8 #include<map>
     9 #include<algorithm>
    10 #include<cstdio>
    11 #include<cmath>
    12 #include<cstring>
    13 #include <cstdio>
    14 #include <cstdlib>
    15 #include<cstring>
    16 int main()
    17 {
    18     int t;
    19     cin>>t;
    20     while(t--)
    21     {
    22         int n;
    23         cin>>n;
    24         int max1=0;
    25         int s;
    26         long long sum=0;
    27         for(int i=0;i<n;i++)
    28         {
    29             cin>>s;
    30             max1=max(max1,s);
    31             sum+=s;
    32         }
    33         if(n==1&&s==1)
    34         {
    35             cout<<"Yes"<<endl;
    36             continue;
    37         }
    38         if(sum-max1>=max1-1)
    39             cout<<"Yes"<<endl;
    40         else
    41             cout<<"No"<<endl;
    42     }
    43     return 0;
    44 }
    View Code
  • 相关阅读:
    UVa 1451 Average (斜率优化)
    POJ 1160 Post Office (四边形不等式优化DP)
    HDU 3507 Print Article (斜率DP)
    LightOJ 1427 Substring Frequency (II) (AC自动机)
    UVa 10245 The Closest Pair Problem (分治)
    POJ 1741 Tree (树分治)
    HDU 3487 Play with Chain (Splay)
    POJ 2828 Buy Tickets (线段树)
    HDU 3723 Delta Wave (高精度+calelan数)
    UVa 1625 Color Length (DP)
  • 原文地址:https://www.cnblogs.com/dulute/p/7289197.html
Copyright © 2011-2022 走看看