Codeforces Round #281 (Div. 2) B 模拟
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| 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[];
ll fi[];
ll s1,s2,sum1,sum2;
int main()
{
scanf("%d",&n);
s1=;
s2=;
sum1=;
sum2=;
int flag=;
for(int i=; i<=n; i++)
{
scanf("%I64d",&exm);
if(exm>)
{
fi[s1++]=exm;
sum1=sum1+exm;
}
else
{
se[s2++]=(-exm);
sum2=sum2-exm;
}
if(i==n)
{
if(exm>)
flag=;
}
}
if(sum1>sum2)
{
cout<<"first"<<endl;
return ;
}
if(sum1<sum2)
{
cout<<"second"<<endl;
return ;
}
if(sum1==sum2)
{
int len=min(s1,s2);
for(int i=; i<len; i++)
{
if(fi[i]!=se[i])
{
if(fi[i]>se[i])
{
cout<<"first"<<endl;
return ;
}
if(fi[i]<se[i])
{
cout<<"second"<<endl;
return ;
}
}
}
if(s1>s2)
{
cout<<"first"<<endl;
return ;
}
if(s1<s2)
{
cout<<"second"<<endl;
return ;
}
if(s1==s2)
{
if(flag)
cout<<"first"<<endl;
else
cout<<"second"<<endl;
}
}
return ;
}
Codeforces Round #281 (Div. 2) B 模拟的更多相关文章
- Codeforces Round #281 (Div. 2) A 模拟
A. Vasya and Football time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- 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 Round #281 (Div. 2) B. Vasya and Wrestling 水题
B. Vasya and Wrestling 题目连接: http://codeforces.com/contest/493/problem/B Description Vasya has becom ...
- Codeforces Round #249 (Div. 2) (模拟)
C. Cardiogram time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Codeforces Round #366 (Div. 2) C 模拟queue
C. Thor time limit per test 2 seconds memory limit per test 256 megabytes input standard input outpu ...
- Codeforces Round #281 (Div. 2)
题目链接:http://codeforces.com/contest/493 A. Vasya and Football Vasya has started watching football gam ...
- Codeforces Round #281 (Div. 2) 解题报告
题目地址:http://codeforces.com/contest/493 A题 写完后就交了,然后WA了,又读了一遍题,没找出错误后就开始搞B题了,后来回头重做的时候才发现,球员被红牌罚下场后还可 ...
- Codeforces Round #281 (Div. 2) D(简单博弈)
题目:http://codeforces.com/problemset/problem/493/D 题意:一个n*n的地图,有两个人在比赛,第一个人是白皇后开始在(1,1)位置,第二个人是黑皇后开始在 ...
随机推荐
- 浅谈PHP中的数组和JS中的数组
最近在做前后端对接的时候,遇到一个问题,前端要求返回的数据格式是左边的,但是我通过json_encode返回到的数据格式是右边的 注意:数据格式从"[]"(数组)变成了&quo ...
- rsync + git发布项目
前言: 更新项目的时候需要将更改的文件一一上传,这样比较麻烦,用版本控制器git +rsync 搭建一个发布服务器,以后发布文件非常方便 首先说下,我这边的更新流程,本地写完之后,git push 到 ...
- JavaScript 事件机制
1 什么是事件 JavaScript 使我们有能力创建动态页面.事件是可以被 JavaScript 侦测到的行为. 网页中的每个元素都可以产生某些可以触发 JavaScript 函数的事件.比方说,我 ...
- vue学习笔记-:class
当items.state为true时使用class='rad2state',否则为rad2(默认).
- python--Matplotlib(一)
基础知识薄弱的同学可以看看一下博客 https://www.cnblogs.com/dev-liu/p/pandas_plt_basic.html https://blog.csdn.net/Notz ...
- python QQ邮件发送邮件
# -*- coding: UTF-8 -*- import smtplib from email.mime.text import MIMEText from email.header import ...
- 3. 与服务器对话:理解 HTTP 协议
0.服务器与本地交换机制 2.详解HTtp服务 (1)与服务器对话的流程 (2)Reque 请求 (3)Response 响应 200 成功 404 没有网页 (4)Get/Post区别 get查询数 ...
- 图解java面试
图解Java面试题:基本语法 2017-02-07 14:34 出处:清屏网 人气:178 评论(0) 内容大纲.png &和&&的区别 &和&&的 ...
- 《Cracking the Coding Interview》——第9章:递归和动态规划——题目10
2014-03-20 04:15 题目:你有n个盒子,用这n个盒子堆成一个塔,要求下面的盒子必须在长宽高上都严格大于上面的.如果你不能旋转盒子变换长宽高,这座塔最高能堆多高? 解法:首先将n个盒子按照 ...
- Percona-Tookit工具包之pt-summary
Preface As a dba,We are obliged to master several basic tools(such as vmstat,top,netstat,ios ...