首页 > 代码库 > codeforces 493B.Vasya and Wrestling 解题报告
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_JUDGE16 freopen("in.txt", "r", stdin);17 #endif // ONLINE_JUDGE18 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 else37 {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 else49 {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 }
codeforces 493B.Vasya and Wrestling 解题报告
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。