• 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
    ");
    45         else if (sum < 0)
    46             printf("second
    ");
    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
    ", mark == 1 ? "first" : "second");
    70             }
    71             else        // 得分序列不相等
    72                 printf("%s
    ", flag == 1 ? "first" : "second");
    73         }
    74     }
    75     return 0;
    76 }
    View Code

         

  • 相关阅读:
    无旋转Treap简介
    bzoj 4318 OSU!
    bzoj 1419 Red is good
    bzoj 4008 亚瑟王
    bzoj 1014 火星人prefix
    更多的莫队
    bzoj 3489 A simple rmq problem
    洛谷 2056 采花
    NOIP 2017 游(划水)记
    UVa 11997 K Smallest Sums
  • 原文地址:https://www.cnblogs.com/windysai/p/4148847.html
Copyright © 2020-2023  润新知