codeforce 6C
来源:互联网 发布:免费手机音量增大软件 编辑:程序博客网 时间:2024/05/21 06:11
http://codeforces.com/problemset/problem/6/C
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>#include <string.h>#include <iostream>using namespace std;int a[100002];int main(){ int n,x,y; while(~scanf("%d",&n)) { int sum=0; int sum1=0; int sum2=0; for(int i=1;i<=n;i++) { scanf("%d",&a[i]); sum+=a[i]; } if(n==1) { printf("1 0\n"); continue; } else if(n==2) { printf("1 1\n"); continue; } for(int i=1;i<n;i++) { sum1+=a[i]; if(sum1>=sum/2.0) { sum1-=a[i]; x=i-1; break; } } for(int i=n;i>0;i--) { sum2+=a[i]; if(sum2>=sum/2.0) { sum2-=a[i]; break; } } //printf("(%d,%d,%d,%d)\n",sum1,sum2,x,n-x); if(sum1<=sum2) x++; printf("%d %d\n",x,n-x); } return 0;}
- codeforce 6C
- codeforce 6C - Alice, Bob and Chocolate
- Codeforce # C. Average Score
- CodeForce 279C
- codeforce 237 C D
- Codeforce C. Barcode
- Codeforce 57C Array
- Codeforce 240C Practice
- Codeforce 332C
- codeforce 370C
- codeforce 400 C
- codeforce 12C map
- codeforce 14C
- codeforce 18C
- codeforce 447C
- codeforce 20140808 C. Boredom
- codeforce 492 C D
- (288C)codeforce
- Arduino 笔记
- More Effective C++笔记
- wince 6.0 开机自启动
- Apache 配置二级域名匹配目录及多个站点配置
- hibernate 映射组成关系
- codeforce 6C
- Struts2拦截器
- 写给过去
- linux下MySQL安装及设置
- 软件开发之业务逻辑
- NanShan 的一段最简单的 CFile 读写文件源码
- Office问题整理连载
- Linux shell脚本中判断参数用法
- linux下查看监听端口对应的进程