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的时间.每次选择机器从小到大开 ...
随机推荐
- java.lang.String cannot be cast to scala.runtime.Nothing Scala中的Nothing类型
经常在写Rdd的时候, 如: val OWNER_ID=row.getAs("OWNER_ID") 等, 运行是可能会报异常 : java.lang.String cannot ...
- Arduino从DHT11读取温湿度数据并显示在1602LCD
硬件清单 Arduino NANO1602LCD + PCF8574T模块YL-47 DHT11模块 连线 1. 连接LCD: PCF8574T模块4pin(Gnd, Vcc, SDA i2c数据, ...
- uri.js的用法事例
来源于:http://smoothprogramming.com/tutorials/get-set-query-string-values-from-url-using-uri-js/ Get or ...
- 【CAS单点登录视频教程】 第05集 -- CAS服务器安装
第一步: 下载cas 服务器 cas-server-3.5.2-release.zip 目录 ----------------------------------------- [CAS单点登录视频教 ...
- intellij idea强制更新索引
intellij idea使用时间长了,许多包安了又卸.卸了又安,导致索引文件有些不正常. 删除~/.Intellij Idea/下的index和cache即可彻底更新.
- Instagram/IGListKit 实践谈(UICollectionView框架)
简单介绍 IGListKit是Instagram推出的新的UICollectionView框架,使用数据驱动,旨在创造一个更快更灵活的列表控件. github地址:https://github.com ...
- 树莓派进阶之路 (025) - ubuntu下使用VNC连接树莓派raspberry(转)
转载:http://www.embbnux.com/2014/03/24/on_ubuntu_use_vnc_connect_raspberry/ 参考: http://elinux.org/R ...
- HDU 2208 唉,可爱的小朋友(DFS)
唉,可爱的小朋友 Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- 【exe4j】如何利用exe4j把java桌面程序生成exe文件
前言: 我们都知道Java可以将二进制程序打包成可执行jar文件,双击这个jar和双击exe效果是一样一样的,但感觉还是不同.其实将java程序打包成exe也需要这个可执行jar文件. 准备: ecl ...
- iOS 修改UITabBar的默认点击行为
项目截图 当我接到如上图这个需求的时候,评估了一下.感觉如上图的效果用自定义UITabBar的方式就可以实现了(做法类似新浪微博的自定义UITabBar中的不规则按钮),没错,就是干.一番折腾之后,我 ...