您的位置:首页 > 其它

B. Vasya and Wrestling

2014-12-25 19:39 225 查看
思路:

  这题主要注意,就是字典序的判断。

  小坑:当两队分数与序列完全一样时,谁投了最后一球谁获胜。

AC Code:

1 #include <iostream>
2 #include <stdio.h>
3 #include <algorithm>
4 #include <cstring>
5 #include <string.h>
6 #include <math.h>
7 #include <queue>
8 #include <stack>
9 #include <stdlib.h>
10 #include <map>
11 using namespace std;
12 #define LL long long
13 #define sf(a) scanf("%d",&(a));
14 #define N 500050
15 char name1
,name2
;
16 int f1
,f2
;
17 int t1,t2;
18 int flag=0;
19 int deal(){
20     //判断f1 与 f2的字典序那个大。
21     int a,b;a=b=0;
22     while(a<t1 && b<t2){
23
24         if(f1[a] == f2[b]){
25             a++;b++;
26             continue;
27         }
28         else if(f1[a]>f2[b]) return 1;
29         else return 0;
30
31     }
32     if(t1==a && t2==b) {
33         if(flag==1) return 1;
34         else return 0;
35     }
36     if(t2==b) return 1;  //t2先完了   t1长,其字典序比较大;
37     return 0;
38 }
39 int main()
40 {
41     int n;//t1=t2=0;
42     LL num1,num2;num1=num2=0;
43     scanf("%d",&n);
44     while(n--){
45         int t;
46         scanf("%d",&t);
47         if(t>0) {
48             num1 += t;
49             flag=1;
50             f1[t1++] = t;
51         }
52         else{
53             num2 += (-t);
54             flag=2;
55             f2[t2++] = (-t);
56         }
57     }
58     if(num1>num2) printf("first\n");
59     else if(num1<num2) printf("second\n");
60     else{
61         if(deal()) printf("first\n");
62         else printf("second\n");
63     }
64     return 0;
65 }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: