码迷,mamicode.com
首页 > 其他好文 > 详细

B. Vasya and Wrestling

时间:2014-12-04 06:14:09      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   ar   color   os   sp   on   div   

思路:

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

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

 

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 }

 

B. Vasya and Wrestling

标签:style   blog   io   ar   color   os   sp   on   div   

原文地址:http://www.cnblogs.com/songacm/p/4141872.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!