Alice, Bob and Chocolate
2012-12-05 21:22
363 查看
1.题目:
2.题意:
有两个人分别从左右两个方向吃巧克力,给定各个店铺的时间,若2人时间相同,让给左边的人
3.代码:
A B C D E C - Alice, Bob and Chocolate Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 6C 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 FAQ | About Virtual Judge | Forum | Discuss | Open Source Project All Copyright Reserved ©2010-2012 HUST ACM/ICPC TEAM Anything about the OJ, please ask in the forum, or contact author:Isun Server Time:
2.题意:
有两个人分别从左右两个方向吃巧克力,给定各个店铺的时间,若2人时间相同,让给左边的人
3.代码:
#include<stdio.h> struct node { int visit; int v; }a[100005]; int main() { int n; int left=0,right=0; int a1=1,a2=1; scanf("%d",&n); for(int i=0;i<n;i++) { scanf("%d",&a[i].v); a[i].visit=0; } int m=n-2;//注意n-2 int k=1; left=a[0].v; right=a[n-1].v; for(int i=0;i<n;i++) { if(left<=right&&a[k].visit==0) { left+=a[k].v; a[k].visit=1; k++; a1++; } else if(left>right&&a[m].visit==0) { right+=a[m].v; a[m].visit=1; m--; a2++; } } if(n==1) printf("1 0\n"); else if(n==2) printf("1 1\n");//分别处理 else printf("%d %d\n",a1,a2); return 0; }
相关文章推荐
- CodeForces 6C - Alice, Bob and Chocolate
- G - Alice, Bob and Chocolate
- Alice, Bob and Chocolate CodeForces - 6C
- Alice, Bob and Chocolate
- Codeforces Round #6——C. Alice, Bob and Chocolate(想法题)
- Codeforces Beta Round #6 (Div. 2 Only) C. Alice, Bob and Chocolate
- CF 6 C. Alice, Bob and Chocolate
- 6C - Alice, Bob and Chocolate
- Round #6 C.Alice, Bob and Chocolate
- codeforces 6C - Alice, Bob and Chocolate
- Round #6 C.Alice, Bob and Chocolate-二分
- codeforces 6C - Alice, Bob and Chocolate
- Codeforces Beta Round #6 (Div. 2 Only) C. Alice, Bob and Chocolate 水题
- NEFU要崛起——第5场 C - Alice, Bob and Chocolate
- codeforce 6C - Alice, Bob and Chocolate
- CF_6C_Alice,BobAndChocolate
- ZOJ 3529 A Game Between Alice and Bob(博弈论-sg函数)
- UVA 1500 - Alice and Bob(博弈)
- hdu 4111 Alice and Bob(中档博弈题)★ ★
- HDU 4268 Alice and Bob