Codeforces Beta Round #6 (Div. 2 Only) C. Alice, Bob and Chocolate 水题
C. Alice, Bob and Chocolate
题目连接:
http://codeforces.com/contest/6/problem/C
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
5
2 9 8 2 7
Sample Output
2 3
Hint
题意
有n个物品,每个物品吃掉的时间是a[i]
一个人从左边开始吃,一个人从右边开始吃
如果两个人同时吃到了一个东西,算左边的。
最后问你左边吃了多少个,右边吃了多少个
题解:
直接暴力就好了……
一个记录左边吃的时间,一个记录右边吃的时间,不停去扫就好了
代码
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+7;
long long a[maxn];
int main()
{
int n;scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%lld",&a[i]);
long long t1=0,t2=0;
int num1=0,num2=0;
int l=1,r=n;
while(l<=r)
{
if(t1<=t2)t1+=a[l++],num1++;
else t2+=a[r--],num2++;
}
cout<<num1<<" "<<num2<<endl;
}
Codeforces Beta Round #6 (Div. 2 Only) C. Alice, Bob and Chocolate 水题的更多相关文章
- Codeforces Beta Round #9 (Div. 2 Only) E. Interesting Graph and Apples 构造题
E. Interesting Graph and Apples 题目连接: http://www.codeforces.com/contest/9/problem/E Description Hexa ...
- Codeforces Beta Round #80 (Div. 2 Only)【ABCD】
Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...
- Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】
Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...
- Codeforces Beta Round #79 (Div. 2 Only)
Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...
- Codeforces Beta Round #77 (Div. 2 Only)
Codeforces Beta Round #77 (Div. 2 Only) http://codeforces.com/contest/96 A #include<bits/stdc++.h ...
- Codeforces Beta Round #76 (Div. 2 Only)
Codeforces Beta Round #76 (Div. 2 Only) http://codeforces.com/contest/94 A #include<bits/stdc++.h ...
- Codeforces Beta Round #75 (Div. 2 Only)
Codeforces Beta Round #75 (Div. 2 Only) http://codeforces.com/contest/92 A #include<iostream> ...
- Codeforces Beta Round #74 (Div. 2 Only)
Codeforces Beta Round #74 (Div. 2 Only) http://codeforces.com/contest/90 A #include<iostream> ...
- Codeforces Beta Round #73 (Div. 2 Only)
Codeforces Beta Round #73 (Div. 2 Only) http://codeforces.com/contest/88 A 模拟 #include<bits/stdc+ ...
随机推荐
- Ubuntu每次开机后提示:检测到系统程序出现问题的解决方法
首先,错误报告存放位置: cd /var/crash/ ls //可以查看错误报告 1 2 sudo rm /var/crash/* //删除该目录下的所有文件 1 但是,这只是删除掉的是错误报告,如 ...
- geoip 扩展包根据ip定位详情
教程:https://laravel-china.org/courses/laravel-package/2024/get-the-corresponding-geo-location-informa ...
- xcode没有ios7的模拟器
xcode7 目前只支持 ios8盒和iOS9的模拟器如果是Yosemite系统,下载xcode7和xcode6.4,两个版本可以共存,然后再下载iOS7默契你如果是EI Caption系统,网上说E ...
- coding.net--多人合作开发git的使用
// 从conding拉下新项目 mkdir test cd test git clone https // 安装cocoapods gem sources --remove https://ruby ...
- Java学习笔记()ArrayList
1.什么是ArrayList ArrayList就是传说中的动态数组,用MSDN中的说法,就是Array的复杂版本,它提供了如下一些好处: 动态的增加和减少元素 实现了ICollection和ILis ...
- ASP.NET MVC 获取计算机字体
//加载计算机上可用的字体 public string LoadFonts() { try { var fontCollection = new InstalledFontCollection(); ...
- 【WPF】RenderTransform和LayoutTransform
布局系统 在WPF中,许多绘图任务通过使用变换(transform)可以变得更加简单——变换是通过不加通告地切换形状或元素使用的坐标系统来改变形状或元素绘制方式的对象.在WPF中,变换的一些类大多继承 ...
- windows环境下模仿Linux环境发起curl请求
1.到官网下载curl工具包 2.在curl.exe目录中使用(使用方式1) 解压下载后的压缩文件,通过cmd命令进入到curl.exe所在的目录. 由于博主使用的是windows 64位 的系统,因 ...
- 洛谷P1438 无聊的数列 [zkw线段树]
题目传送门 无聊的数列 题目背景 无聊的YYB总喜欢搞出一些正常人无法搞出的东西.有一天,无聊的YYB想出了一道无聊的题:无聊的数列...(K峰:这题不是傻X题吗) 题目描述 维护一个数列{a[i]} ...
- Python并发编程-进程池的返回值
同步或异步获取返回值 #p = Pool() #p.map(funcname,iterable) 默认异步的执行任务,且自带close,join功能 #p.apply(), 同步调用进程池的方法 #p ...