CodeForces 6C Alice, Bob and Chocolate
2016-04-06 21:30
323 查看
题意:有n个物品,每个物品吃掉的时间是a[i],一个人从左边开始吃,一个人从右边开始吃,如果两个人同时吃到了一个东西,算左边的。最后问你左边吃了多少个,右边吃了多少个
思路:直接暴力扫吧...
Description
Alice and Bob like games. And now they are ready to start a new game. They have placed n chocolate bars in a line. Alice starts to eat chocolate bars one by one from left to right, and Bob
— from right to left. For each chocololate bar the time, needed for the player to consume it, is known (Alice and Bob eat them with equal speed). When the player consumes a chocolate bar, he immediately starts with another. It is not allowed to eat two chocolate
bars at the same time, to leave the bar unfinished and to make pauses. If both players start to eat the same bar simultaneously, Bob leaves it to Alice as a true gentleman.
How many bars each of the players will consume?
Input
The first line contains one integer n (1 ≤ n ≤ 105) — the amount of bars on the table. The second
line contains a sequence t1, t2, ..., tn(1 ≤ ti ≤ 1000),
where ti is the time (in seconds) needed to consume the i-th bar (in the order from left
to right).
Output
Print two numbers a and b, where a is the amount of bars consumed
by Alice, and b is the amount of bars consumed by Bob.
Sample Input
Input
Output
思路:直接暴力扫吧...
#include<bits/stdc++.h> using namespace std; const int maxn = 1e5+7; long long a[maxn]; int main() { int n;scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%lld",&a[i]); long long t1=0,t2=0; int num1=0,num2=0; int l=1,r=n; while(l<=r) { if(t1<=t2)t1+=a[l++],num1++; else t2+=a[r--],num2++; } cout<<num1<<" "<<num2<<endl; }
Description
Alice and Bob like games. And now they are ready to start a new game. They have placed n chocolate bars in a line. Alice starts to eat chocolate bars one by one from left to right, and Bob
— from right to left. For each chocololate bar the time, needed for the player to consume it, is known (Alice and Bob eat them with equal speed). When the player consumes a chocolate bar, he immediately starts with another. It is not allowed to eat two chocolate
bars at the same time, to leave the bar unfinished and to make pauses. If both players start to eat the same bar simultaneously, Bob leaves it to Alice as a true gentleman.
How many bars each of the players will consume?
Input
The first line contains one integer n (1 ≤ n ≤ 105) — the amount of bars on the table. The second
line contains a sequence t1, t2, ..., tn(1 ≤ ti ≤ 1000),
where ti is the time (in seconds) needed to consume the i-th bar (in the order from left
to right).
Output
Print two numbers a and b, where a is the amount of bars consumed
by Alice, and b is the amount of bars consumed by Bob.
Sample Input
Input
5 2 9 8 2 7
Output
2 3
相关文章推荐
- python中__init__.py文件的作用
- eclipse远程连接hadoop单机模式出现的问题
- [sql]MySQL数据备份小结
- Maven项目管理(一) IntelliJ Idea+Maven环境搭建与基于命令行的基本使用
- LeetCode--sort-list
- AlertDialog弹出对话框条件不成立不消失
- 添加约束及打印五角星及查询
- CentOS下添加sudo用户
- HDU2039
- EF中的来自数据库的EF设计器和来自数据库的CodeFirst的区别
- Android 操作数据库的框架——greenDAO的学习
- 唯品会面试经历分享
- 有一个贝塔炸弹,2014年11月9日放置,定时为1000天
- Vijos1579:宿命的PSS
- Python 练习册,每天一个小程序(0007)
- 闲说App的接口测试
- 4.6日 js call css classList js 拖拽 十个心得
- CodeForces 6B President's Office
- java(20)--单例模式总结
- Android学习之CardView文档翻译