B. Vasya and Wrestling

思路:

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

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

 

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[N],name2[N];
16 int f1[N],f2[N];
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 }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值