codeforces 493B.Vasya and Wrestling 解题报告

题目链接:http://codeforces.com/problemset/problem/493/B

题目意思:给出 n 个 techniques,每个 technique 的值为 ai。 ai > 0 表示把这个分数给第一个wrestler,ai < 0,表示给第二个wrestler。约定 ai != 0。

  如果两个人最终的得分不相等,分数多的那个人获胜。

  如果两个人最终的得分相等,可以分两种情况讨论:

  (1)序列中至少有一位不相等,那么字典序大的那个获胜。例如第一个人:1, 4, 5, 8 ,第二个人: 2, 3, 6, 7,总和都为18。那么第二个人胜。

  (2)序列中每位都相等,那么最后得分的那个人获胜。例如给出的 n 个数为 -4, 4,那么第一个人获胜。

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstdlib>
 4 #include <cstring>
 5 #include <algorithm>
 6 using namespace std;
 7 
 8 typedef __int64 LL;
 9 const int maxn = 2e5 + 5;
10 int a[maxn], b[maxn];
11 LL sum;
12 
13 int main()
14 {
15     #ifndef ONLINE_JUDGE
16         freopen("in.txt", "r", stdin);
17     #endif // ONLINE_JUDGE
18 
19     int n, in;
20     while (scanf("%d", &n) != EOF)
21     {
22         sum = 0;      
23         int mark;
24         int l1 = 0, l2 = 0;
25 
26         for (int i = 0; i < n; i++)
27         {
28             scanf("%d", &in);
29             sum += in;
30 
31             if (in > 0)
32             {
33                 a[l1++] = in;
34                 mark = 1;
35             }
36             else
37             {
38                 b[l2++] = -in;
39                 mark = 2;
40             }
41         }
42         // 最终的得分不相等
43         if (sum > 0)
44             printf("first\n");
45         else if (sum < 0)
46             printf("second\n");
47         // 最终的得分相等
48         else
49         {
50             int flag = 0;
51 
52             for (int i = 0; i < l1 && i < l2; i++)   // 两条得分序列中至少有一位不相等
53             {
54                 if (a[i] > b[i])
55                 {
56                     flag = 1;
57                     break;
58                 }
59                 else if (a[i] < b[i])
60                 {
61                     flag = 2;
62                     break;
63                 }
64             }
65             
66             if (!flag)   // 两条得分序列相等时,最后得分的那个人获胜
67             {
68                 if (l1 == l2)
69                     printf("%s\n", mark == 1 ? "first" : "second");
70             }
71             else        // 得分序列不相等
72                 printf("%s\n", flag == 1 ? "first" : "second");
73         }
74     }
75     return 0;
76 }
View Code

 

     

转载于:https://www.cnblogs.com/windysai/p/4148847.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值