博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CodeForces 6C
阅读量:5818 次
发布时间:2019-06-18

本文共 1538 字,大约阅读时间需要 5 分钟。

题目链接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?
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 test(s)
Input
5
2 9 8 2 7
Output
2 3

题目大意就是从Alice从左往右,Bob从右往左看谁吃了多少,简单贪心一步就完成

1 #include
2 int a[100005]; 3 int main() 4 { 5 int m; 6 scanf("%d",&m); 7 int i,j; 8 for(i=0;i
q){i-=1;p-=q;q=a[j-1];}14 else if(p==q){p=a[i+1];q=a[j-1];}15 }16 printf("%d %d\n",i,m-i);17 return 0;18 }

 

转载于:https://www.cnblogs.com/gj-Acit/archive/2013/02/10/2909782.html

你可能感兴趣的文章
linux中内存使用原理
查看>>
量子回路终于制成,量子计算机指日可待
查看>>
12 Open Source Projects by Alibaba – Part 1
查看>>
python【4】-函数
查看>>
调整窗口大小也能够实现div水平垂直居中代码实例
查看>>
PostgreSQL数据库 OLTP高并发请求性能优化
查看>>
联想2017TechWorld大会举行 联想未来瞄准AI
查看>>
出国就医不用慌,日本推出“医用语音翻译系统”
查看>>
ansible常用模块详解
查看>>
开启人工智能新时代,首款神经网络处理器“寒武纪”即将上市
查看>>
大神解答:如何实现域账号免登陆流程平台的功能
查看>>
干货|全面分析GAN,以及如何用TF实现GAN?
查看>>
cas4.2.7实现单点登录
查看>>
Win7下Python2.7配置
查看>>
C#程序结构
查看>>
【Android手机游戏】贪吃蛇(1)
查看>>
解决IP地址冲突的方法--DHCP SNOOPING
查看>>
How to Detect and Respond to Malware-Free Intrusions
查看>>
Office动画技巧集锦
查看>>
网站提速-缓存技术(5)
查看>>