【codeforces】378BParade(简单思维+英语阅读理解-.-)
来源:互联网 发布:js 正则表达式 编辑:程序博客网 时间:2024/04/28 08:55
Very soon there will be a parade of victory over alien invaders in Berland. Unfortunately, all soldiers died in the war and now the army consists of entirely new recruits, many of whom do not even know from which leg they should begin to march. The civilian population also poorly understands from which leg recruits begin to march, so it is only important how many soldiers march in step.
There will be n columns participating in the parade, the i-th column consists of li soldiers, who start to march from left leg, and risoldiers, who start to march from right leg.
The beauty of the parade is calculated by the following formula: if L is the total number of soldiers on the parade who start to march from the left leg, and R is the total number of soldiers on the parade who start to march from the right leg, so the beauty will equal |L - R|.
No more than once you can choose one column and tell all the soldiers in this column to switch starting leg, i.e. everyone in this columns who starts the march from left leg will now start it from right leg, and vice versa. Formally, you can pick no more than one index iand swap values li and ri.
Find the index of the column, such that switching the starting leg for soldiers in it will maximize the the beauty of the parade, or determine, that no such operation can increase the current beauty.
The first line contains single integer n (1 ≤ n ≤ 105) — the number of columns.
The next n lines contain the pairs of integers li and ri (1 ≤ li, ri ≤ 500) — the number of soldiers in the i-th column which start to march from the left or the right leg respectively.
Print single integer k — the number of the column in which soldiers need to change the leg from which they start to march, or 0 if the maximum beauty is already reached.
Consider that columns are numbered from 1 to n in the order they are given in the input data.
If there are several answers, print any of them.
35 68 910 3
3
26 55 6
1
65 91 34 84 523 5412 32
0
In the first example if you don't give the order to change the leg, the number of soldiers, who start to march from the left leg, would equal5 + 8 + 10 = 23, and from the right leg — 6 + 9 + 3 = 18. In this case the beauty of the parade will equal |23 - 18| = 5.
If you give the order to change the leg to the third column, so the number of soldiers, who march from the left leg, will equal5 + 8 + 3 = 16, and who march from the right leg — 6 + 9 + 10 = 25. In this case the beauty equals |16 - 25| = 9.
It is impossible to reach greater beauty by giving another orders. Thus, the maximum beauty that can be achieved is 9.
求交换次序后,第几行能实现|R-L|最大。
#include<cstdio>#include<iostream>#include<cstring>#include<cmath>#include<algorithm>#include<map>#define LL long longusing namespace std;const int N = 100000+10;int r[N],l[N];int main(){int n;while(scanf("%d",&n)!=EOF){int L=0,R=0;for(int i=0;i<n;i++){scanf("%d%d",&r[i],&l[i]);L+=l[i];R+=r[i];}int ans=0;int maxn=abs(L-R);for(int i=0;i<n;i++){L-=l[i];R-=r[i];L+=r[i];R+=l[i];if(abs(L-R)>maxn){maxn=abs(L-R);ans=i+1;}L-=r[i];R-=l[i];L+=l[i];R+=r[i];}printf("%d\n",ans);}return 0;}
- 【codeforces】378BParade(简单思维+英语阅读理解-.-)
- 专业英语(阅读理解)
- 考研英语阅读理解总结
- GCT英语阅读理解常见问题分析
- 英语思维
- codeforces 359A- Table(简单思维)
- 【Codeforces 729D Sea Battle】+ 简单思维
- 英语阅读
- 英语阅读
- 考研英语阅读理解七篇经典文章解析(7)
- 考试大考博经验谈:考博英语阅读理解
- 英语阅读理解中表示作者态度的词汇汇总
- 如何提高英语的阅读理解【很经典的学习方法】
- 2011考研英语大纲与阅读理解100天…
- 2018医学考博英语阅读理解解题技巧
- 用英语思维学习英语
- 英语思维VS汉语思维
- 思维 CodeForces
- 何为高质量的代码
- 矩阵的掩模操作(锐化举例)
- 如何使用repo下载部分Android源码并保持项目结构
- BZOJ 1098: [POI2007]办公楼biu 并查集优化bfs找反图联通块
- Python菜鸟--pass语句
- 【codeforces】378BParade(简单思维+英语阅读理解-.-)
- 初识Java——多线程
- 【codeforces 731D】【差分+线段扫描 思维题】80-th Level Archeology【给你n个word,现在要使得word按字典序排列,随便操作多少次,每次可以使每个word+1】
- Centos下安装Oracle 11g
- c数组
- HBase Shell
- 10012---Linux命令 vim下的查找
- 自己解决的小问题-JRE System Library[jdk1.7找不到
- 俄罗斯4岁女孩会7门语言 中文又流利又激萌