Title Link: Http://codeforces.com/problemset/problem/493/B
The title means: Give n techniques, each technique value is AI. Ai > 0 means to give this score to the first Wrestler,ai < 0 for the second wrestler. Convention AI! = 0.
If two people end up with a score that is not equal, the person who scores more wins.
If the final score of two people is equal, it can be discussed in two different situations:
(1) At least one of the sequences is unequal, then the one with the larger dictionary order wins. For example, the first person: 1, 4, 5, 8, second person: 2, 3, 6, 7, the sum is 18. Then the second one wins.
(2) Each of the sequences is equal, then the person who scored the last one wins. For example, the number of n given is-4, 4, then the first person wins.
1#include <iostream>2#include <cstdio>3#include <cstdlib>4#include <cstring>5#include <algorithm>6 using namespacestd;7 8 typedef __int64 LL;9 Const intMAXN = 2e5 +5;Ten intA[MAXN], B[MAXN]; One LL sum; A - intMain () - { the #ifndef Online_judge -Freopen ("In.txt","R", stdin); - #endif //Online_judge - + intNinch; - while(SCANF ("%d", &n)! =EOF) + { Asum =0; at intMark; - intL1 =0, L2 =0; - - for(inti =0; I < n; i++) - { -scanf"%d", &inch); inSum + =inch; - to if(inch>0) + { -a[l1++] =inch; theMark =1; * } $ ElsePanax Notoginseng { -b[l2++] =-inch; theMark =2; + } A } the //The final score is not equal + if(Sum >0) -printf"first\n"); $ Else if(Sum <0) $printf"second\n"); - //The final score is equal - Else the { - intFlag =0;Wuyi the for(inti =0; I < L1 && I < L2; i++)//at least one of the two scoring sequences is not equal - { Wu if(A[i] >B[i]) - { AboutFlag =1; $ Break; - } - Else if(A[i] <B[i]) - { AFlag =2; + Break; the } - } $ the if(!flag)//when the two scoring sequences are equal, the person who scored last wins. the { the if(L1 = =L2) theprintf"%s\n", Mark = =1?" First":"Second"); - } in Else //scoring sequences are not equal theprintf"%s\n", flag = =1?" First":"Second"); the } About } the return 0; the}
View Code
Codeforces 493B. Vasya and wrestling Problem solving report