Alice, Bob and Chocolate
来源:互联网 发布:自学英语入门软件 编辑:程序博客网 时间:2024/05/17 01:52
模拟一下就好了
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?
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).
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.
52 9 8 2 7
2 3
#include<stdio.h>int main(){int n,a,b,j,k,cnta,cntb,sum=0,an[100005]={0};scanf("%d",&n);for(int i=0;i<n;i++){scanf("%d",&an[i]);sum+=an[i];}a=0,b=0,j=0,k=n-1,cnta=0,cntb=0;while(a+b<sum){if(a<=b){a+=an[j++];cnta++;}else{b+=an[k--];cntb++;}}printf("%d %d",cnta,cntb);return 0;}
- Alice, Bob and Chocolate
- Alice, Bob and Chocolate
- G - Alice, Bob and Chocolate
- Alice, Bob and Chocolate CodeForces
- codeforces 6C - Alice, Bob and Chocolate
- Round #6 C.Alice, Bob and Chocolate
- Codeforces 6C. Alice, Bob and Chocolate
- CF 6C Alice, Bob and Chocolate
- CodeForces 6C - Alice, Bob and Chocolate
- CodeForces 6C Alice, Bob and Chocolate
- 6C - Alice, Bob and Chocolate
- codeforce 6C - Alice, Bob and Chocolate
- CodeForces 6C Alice, Bob and Chocolate
- Round #6 C.Alice, Bob and Chocolate-二分
- Alice and Bob
- 2683. Alice and Bob
- 1798. Alice and Bob
- hdu4268 Alice and Bob
- OkHttp使用
- Retrofit2 & RxJava2实现单文件和多文件上传
- numpy的delete删除数组整行和整列
- java设计模式-- 策略模式
- Oracle 基础(3)——插入数据
- Alice, Bob and Chocolate
- 【已解决】springmvc出现的未找到处理器异常可能原因
- JAVA实现二叉树的前、中、后序遍历(递归与非递归)
- 解惑 spring 嵌套事务
- http和https的区别
- Android百度地图导航的那些坑
- clipToPadding 和 clipChildren
- The Google File System : part5 FAULT TOLERANCE AND DIAGNOSIS
- 新手入门-20170904-如何愉快地在 docker 环境下玩耍 TF