CF_6C_Alice,BobAndChocolate
2016-03-30 20:51
603 查看
C. Alice, Bob and Chocolate
time limit per test
2 seconds
memory limit per test
64 megabytes
input
standard input
output
standard output
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.
Examples
input
output
AB两个人一起吃好多巧克力棒
巧克力棒排一排
两人从这一排的两端开始吃
给出吃每个棒的时间然后问各吃了多少
如果两个人要同时吃一根时 B会让给A
从两边开始扫即可
time limit per test
2 seconds
memory limit per test
64 megabytes
input
standard input
output
standard output
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.
Examples
input
5 2 9 8 2 7
output
2 3
AB两个人一起吃好多巧克力棒
巧克力棒排一排
两人从这一排的两端开始吃
给出吃每个棒的时间然后问各吃了多少
如果两个人要同时吃一根时 B会让给A
从两边开始扫即可
#include <iostream> #include <stdio.h> using namespace std; const int M=1e5+5; int ti[M]; int main() { int n; scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&ti[i]); int pa=1,pb=n; while(pa<pb) { if(ti[pa]==ti[pb]) { if(pa+1==pb) break; if(pa++==pb--) break; continue; } if(ti[pa]>ti[pb]) { if(pb-1==pa) break; ti[pa]-=ti[pb--]; continue; } if(ti[pb]>ti[pa]) { if(pa+1==pb) break; ti[pb]-=ti[pa++]; continue; } } printf("%d %d\n",pa,n-pa); return 0; }
相关文章推荐
- 字符串过滤器(华为上机题)
- android优化(json工具,message新建/传递,avtivity深入学习视频)
- BP神经网络与RBF神经网络讲得好的博客链接
- hdu3065(AC自动机)
- 第三周项目4-穷举法解决百钱百鸡问题
- 【JavaScript】基础知识整理(三)
- 在家里免费下载知网内的论文方法
- 算法介绍(一)
- S3C2440-GPIO之button
- 实用代码片段--Javascript
- 一种适合创业公司的技术架构方案
- 二维数组和arraycopy
- hdu 1217 Arbitrage 最短路 floyd+map容器
- 杭电1032
- 扣丁学堂笔记第16天SQLite数据库
- IT行业导览-4.3-数据分析师
- JNI/NDK开发指南(一)—— JNI开发流程及HelloWorld
- ZOJ2539 Energy Minimization(最小割)
- Shiro Quartz之Junit測试Session管理
- Python Select 解析