CodeForces 493B Vasya and Wrestling 【模拟】
2 seconds
256 megabytes
standard input
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.
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.
If the first wrestler wins, print string "first", otherwise print "second"
5
1
2
-3
-4
3
second
3
-1
-2
3
first
2
4
-4
second
Sequence x = x1x2... x|x| is lexicographically
larger than sequence y = y1y2... y|y|,
if either |x| > |y| and x1 = y1, x2 = y2, ...
, x|y| = y|y|,
or there is such number r (r < |x|, r < |y|),
that x1 = y1, x2 = y2, ...
, xr = yr and xr + 1 > yr + 1.
We use notation |a| to denote length of sequence a.
一定要注意是不是会越界啊!
!。!
代码:
#include <stdio.h>
#include <string.h>
#define M 250050
typedef unsigned long long LL; int a[M], b[M]; int main(){
int n;
while(~scanf("%d", &n)){
int temp, i, j;
int flag = -1, la, lb;
la = lb = 0;
LL sum1, sum2;
sum1 = sum2 = 0;
for(i = 0; i < n; i ++){
scanf("%d", &temp);
if(temp > 0){
sum1 +=temp;
flag = 1;
a[la++] = temp;
}
else {
temp = -temp;
sum2 += temp;
flag = 2;
b[lb++] = temp;
}
}
if(sum1 > sum2){
printf("first\n");
}
else if(sum1 < sum2){
printf("second\n");
}
else{
i = 0; j = 0;
int ok = 0;
while(i<la&&j<lb){
if(a[i] == b[j]){
++i; ++j;
}
else{
if(a[i] > b[j]) puts("first");
else puts("second");
return 0;
}
}
if(la >lb){
printf("first\n"); return 0;
}
if(la < lb){
printf("second\n");
return 0;
}
if(flag == 1) printf("first\n");
else printf("second\n");
}
}
return 0;
}
CodeForces 493B Vasya and Wrestling 【模拟】的更多相关文章
- codeforces 493B.Vasya and Wrestling 解题报告
题目链接:http://codeforces.com/problemset/problem/493/B 题目意思:给出 n 个 techniques,每个 technique 的值为 ai. ai & ...
- Codeforces Round #281 (Div. 2) B. Vasya and Wrestling 水题
B. Vasya and Wrestling 题目连接: http://codeforces.com/contest/493/problem/B Description Vasya has becom ...
- cf493B Vasya and Wrestling
B. Vasya and Wrestling time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- CodeForces - 837E - Vasya's Function | Educational Codeforces Round 26
/* CodeForces - 837E - Vasya's Function [ 数论 ] | Educational Codeforces Round 26 题意: f(a, 0) = 0; f( ...
- CodeForces.158A Next Round (水模拟)
CodeForces.158A Next Round (水模拟) 题意分析 校赛水题的英文版,坑点就是要求为正数. 代码总览 #include <iostream> #include &l ...
- Codeforces Round #281 (Div. 2) A. Vasya and Football 模拟
A. Vasya and Football 题目连接: http://codeforces.com/contest/493/problem/A Description Vasya has starte ...
- Codeforces Round #281 (Div. 2) A. Vasya and Football(模拟)
简单题,却犯了两个错误导致WA了多次. 第一是程序容错性不好,没有考虑到输入数据中可能给实际已经罚下场的人再来牌,这种情况在system测试数据里是有的... 二是chronologically这个词 ...
- codeforces C. Vasya And The Mushrooms (思维+模拟)
题意:给定一个2*n的矩形方格,每个格子有一个权值,从(0,0)开始出发,要求遍历完整个网格(不能重复走一个格子),求最大权值和,(权值和是按照step*w累加,step步数从0开始). 转载: 题解 ...
- Codeforces 747C:Servers(模拟)
http://codeforces.com/problemset/problem/747/C 题意:有n台机器,q个操作.每次操作从ti时间开始,需要ki台机器,花费di的时间.每次选择机器从小到大开 ...
随机推荐
- 触发JVM进行Full GC的情况及应对策略
堆内存划分为 Eden.Survivor 和 Tenured/Old 空间,如下图所示: 从年轻代空间(包括 Eden 和 Survivor 区域)回收内存被称为 Minor GC,对老年代GC称为M ...
- Inno Setup入门(十)——操作注册表
有些程序需要随系统启动,或者需要建立某些文件关联等问题,这些都是通过在安装程序中对注册表进行操作的结果.Inno Setup中通过[registry]段实现对注册表的操作. 本段说明: 参数列表: 参 ...
- Delta3D Open Source Engine
在看<游戏编程精粹6>时看到了这个引擎,彩插7是这个引擎的Editor,我一看就是Qt写的,我太熟悉Qt的界面了,呵呵.Editor非常强悍!有类似3dmax的4个视图 下载这个看下吧,里 ...
- 转:Irrlicht 0.1引擎源码分析与研究(一)
目录(?)[-] 主要技术特性 引擎概览 Irrlicht的窗口管理 Irrlicht引擎主要是由一个名叫Nikolaus Gebhardt奥地利人所设计,是sourceforge上的一个开源项目 ...
- SqlServer安装时的选项说明
转自:https://blog.csdn.net/m0_37154839/article/details/80233446 看看组件的功能说明吧 服务器组件 说明 SQL Server 数据库引擎 S ...
- Android开发环境——调试器 DDMS相关内容汇总
Android开发环境将分为SDK相关内容.Eclipse ADT相关内容.模拟器AVD相关内容.调试器DDMS相关内容.日志LogCat相关内容.连接驱动ADB相关内容.内存泄露检测工具MAT ...
- libev与libevent区别
摘自stackflow的回答,主要从架构上说明了二者的区别: As for design philosophy, libev was created to improve on some of the ...
- zabbix主动被动模式说明/区别
说明:使用zabbix代理有很多好处,一方面可以监控不可达的远程区域:另一方面当监控项目数以万计的时候使用代理可以有效分担zabbix server压力,也简化分布式监控的维护. 具体:主动.被动模式 ...
- 上海租房找房建议及条件,上海IT行业开发常见公司的位置地点
上海租房,找房条件 以2号地铁线为中心,优先选择(回家方便,重点!),交通设施较集中地铁:2,3,4 区:普陀区,静安区,长宁区,闸北区,浦东新区,闵行区,徐汇区 路:镇坪路,威宁路,娄山关路,中山公 ...
- .net获取当前url各种属性(文件名、参数、域名、端口等)的方法(转)
假设当前页完整地址是:http://www.test.com:80/aaa/bbb.aspx?id=5&name=kelli "http://"是协议名 "www ...