Codeforces Round #281 (Div. 2) B 模拟
2016-07-25 13:47
435 查看
B. Vasya and Wrestling
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
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"
Examples
input
output
input
output
input
output
Note
Sequence x = x1x2... x|x| is lexicographically larger than sequence y = y1y2... y|y|, if either |x| > |y| andx1 = y1, x2 = y2, ... , x|y| = y|y|, or there is such number r (r < |x|, r < |y|), that x1 = y1, x2 = y2, ... , xr = yr andxr + 1 > yr + 1.
We use notation |a| to denote length of sequence a.
题意:
现有两个人first和second,然后给出一系列的值,值为正则赋值给first,值为负则把它的绝对值赋给second,然后进行判断:
1:如果first和second得到的值不相等,则输出得到值多的那个人。
2:如果值相等,这时候就比较输入中这些值的大小,一旦出现不相等的值,输出值大的那一方。
3:如果还有相等的情况,输出得到最后一个值的那一个人。
题解:模拟
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
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"
Examples
input
5 1 2 -3 -4 3
output
second
input
3 -1 -2 3
output
first
input
2 4 -4
output
second
Note
Sequence x = x1x2... x|x| is lexicographically larger than sequence y = y1y2... y|y|, if either |x| > |y| andx1 = y1, x2 = y2, ... , x|y| = y|y|, or there is such number r (r < |x|, r < |y|), that x1 = y1, x2 = y2, ... , xr = yr andxr + 1 > yr + 1.
We use notation |a| to denote length of sequence a.
题意:
现有两个人first和second,然后给出一系列的值,值为正则赋值给first,值为负则把它的绝对值赋给second,然后进行判断:
1:如果first和second得到的值不相等,则输出得到值多的那个人。
2:如果值相等,这时候就比较输入中这些值的大小,一旦出现不相等的值,输出值大的那一方。
3:如果还有相等的情况,输出得到最后一个值的那一个人。
题解:模拟
//code by drizzle #include<bits/stdc++.h> #include<iostream> #include<cstring> #include<cstdio> #include<algorithm> #include<vector> #include<queue> #include<stack> //#define ll long long #define ll __int64 #define PI acos(-1.0) #define mod 1000000007 using namespace std; int n; ll exm; ll se[200005]; ll fi[200005]; ll s1,s2,sum1,sum2; int main() { scanf("%d",&n); s1=0; s2=0; sum1=0; sum2=0; int flag=0; for(int i=1; i<=n; i++) { scanf("%I64d",&exm); if(exm>0) { fi[s1++]=exm; sum1=sum1+exm; } else { se[s2++]=(-exm); sum2=sum2-exm; } if(i==n) { if(exm>0) flag=1; } } if(sum1>sum2) { cout<<"first"<<endl; return 0; } if(sum1<sum2) { cout<<"second"<<endl; return 0; } if(sum1==sum2) { int len=min(s1,s2); for(int i=0; i<len; i++) { if(fi[i]!=se[i]) { if(fi[i]>se[i]) { cout<<"first"<<endl; return 0; } if(fi[i]<se[i]) { cout<<"second"<<endl; return 0; } } } if(s1>s2) { cout<<"first"<<endl; return 0; } if(s1<s2) { cout<<"second"<<endl; return 0; } if(s1==s2) { if(flag) cout<<"first"<<endl; else cout<<"second"<<endl; } } return 0; }
相关文章推荐
- 对称加密与非对称加密的区别
- java中的内部内总结
- 多线程同步
- android通过获取摄像头照片,实时与点传输
- CockroachDB 测试
- Description Resource Path Location Type Java compiler level does not match the version of the instal
- 基于按annotation的hibernate主键生成策略
- 套 接 字 →
- 大数据技能图谱
- Struts2约定优于配置
- 《上帝的跳蚤》2016060211-》2016070514
- hdu 3987 求割边最少的最小割
- 《CSS3权威指南》——笔记4(值和单位)
- MySQL 单表百万数据记录分页性能优化
- jstl表达式
- [shell基础]——I/O重定向
- 那年的雨季
- 使用ajax和window.history.pushState无刷新改变页面内容和地址栏URL
- mysql 修改max_connections
- @RequestBody应用