B. Vasya and Wrestling
题目连接:
http://codeforces.com/contest/493/problem/B
Description
Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins.
When the numbers of points of both wrestlers are equal, the wrestler whose sequence of points is lexicographically greater, wins.
If the sequences of the awarded points coincide, the wrestler who performed the last technique wins. Your task is to determine which wrestler won.
Input
The first line contains number n — the number of techniques that the wrestlers have used (1 ≤ n ≤ 2·105).
The following n lines contain integer numbers ai (|ai| ≤ 109, ai ≠ 0). If ai is positive, that means that the first wrestler performed the technique that was awarded with ai points. And if ai is negative, that means that the second wrestler performed the technique that was awarded with ( - ai) points.
The techniques are given in chronological order.
Output
If the first wrestler wins, print string “first”, otherwise print “second”
Sample Input
5
1
2
-3
-4
3
Sample Output
second
Hint
题意
有n个分数,然后输入,如果是正数,那么就属于第一个人,如果是负数,那么就属于第二个人。
谁分数大,谁胜利。
如果分数一样,那么看字典序大小。
如果字典序大小一样,看最后的那个数属于谁
题解:
读题比做题难……
模拟一下就好了
代码
#include<bits/stdc++.h>
using namespace std;
vector<int> a,b;
int judge()
{
for(int i=0;i<a.size()&&i<b.size();i++)
{
if(a[i]>b[i])return 1;
if(b[i]>a[i])return 2;
}
return 0;
}
int main()
{
int n;
long long sum1=0,sum2=0;
scanf("%d",&n);
int flag = 0;
for(int i=0;i<n;i++)
{
int x;scanf("%d",&x);
if(x>0)
{
a.push_back(x);
sum1+=x;
flag = 1;
}
else
{
b.push_back(-x);
sum2+=-x;
flag = 2;
}
}
if(sum1>sum2)return puts("first"),0;
if(sum2>sum1)return puts("second"),0;
if(judge()==1)return puts("first"),0;
else if(judge()==2)return puts("second"),0;
if(flag==1)return puts("first"),0;
else return puts("second"),0;
}