HDOJ 1205 eats candy, hdoj1205 eats candy
Eat candyTime Limit: 6000/3000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission (s): 23456 Accepted Submission (s): 6747
Problem DescriptionHOHO, finally won all the sweets from the Speakless hand. It is a special hobby for Gardon to eat candy, that is, they do not like to put the same candy together, they like to eat one first, the next time you eat the other one, this way; but Gardon doesn't know if there is a sequence of eating candy so that he can finish all the candy? Please write a program for computation.
The first line of Input has an integer T, followed by the T group of data, each group of data occupies 2 rows, the first row is an integer N (0 <N <= 1000000 ), the second row is the number of N, indicating the number of N kinds of candy Mi (0 <Mi <= 1000000 ).
Output outputs a row for each group of data, including a "Yes" or "No ".
Sample Input
234 1 155 4 3 2 1
Sample Output
NoYesHintHint Please use function scanf
Water problems, with the basic drawer away. (PS. I didn't know how to do it at the beginning. I have too few questions)
Drawer principle, that is, the number can be arranged into a column at most, and then the remaining is used as a partition to check whether it can be implemented.
In the first example of daily life, assume that the value of 4 1 is a B c, and the value of A is a B A C A. A is not satisfied because AA occurs, and No is output.
Code:
#include <cstdio>int main(){int T, n, temp,max;long long sum;scanf("%d", &T);while (T--){temp = sum = max=0;scanf("%d", &n);while (n--){scanf("%d", &temp);if (max < temp)max = temp;sum += temp;}if (sum - max >= max - 1)printf("Yes\n");elseprintf("No\n");}return 0;}
Sample Output
NoYesHintHint Please use function scanf
HDOJ 1205 eat candy java
I don't understand the meaning of your input multiple times. I didn't mark comments in the Code. Can I write a more complete description of the question?
ACM question, answer
Three questions
Sum = 0 should be written in the loop
The no condition is a> sum + 1.
The data type of sum should be long.
Let's just talk about it.
Appendix: modified code
Problem: 1205 (eat candy) Judge Status: Accepted
RunId: 3050346 Language: G ++ Author: ccarter
Code Render Status: Rendered By hdoj g ++ Code Render Version 0.01 Beta
# Include <stdio. h>
Int main ()
{
Int t, a, B, c, n;
Long sum;
Scanf ("% d", & t );
For (int I = 0; I <t; I ++)
{Scanf ("% d", & n );
Sum = 0;
Scanf ("% d", & );
For (int j = 0; j <n-1; j ++)
{Scanf ("% d", & B );
If (a <B)
{C =;
A = B;
B = c ;}
Sum + = B ;}
If (a> sum + 1)
Printf ("No \ n ");
Else
Printf ("Yes \ n ");
}
Return 0;
}
# Include <stdio. h>
Int main ()
{
Int t, a, B, c, n;
Long sum;
Scanf ("% d", & t );
For (int I = 0; I <t; I ++)
{Scanf ("% d", & n );
Sum = 0;
Scanf ("% d", & );
For (int j = 0; j <n-1; j ++)
{Scanf ("% d", & B );
If (a <B)
{C =;
A = B;
B = c ;}
Sum + = B ;}
If (a> sum + 1)
Printf ("No \ n ");
Else
Printf ("Yes \ n ");
}
Return 0;
}