Educational Codeforces Round 42 (Rated for Div. 2) A
2 seconds
256 megabytes
standard input
standard output
Polycarp has created his own training plan to prepare for the programming contests. He will train for nn days, all days are numbered from 11to nn, beginning from the first.
On the ii-th day Polycarp will necessarily solve aiai problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on the first evening of such a day that from the beginning of the training and to this day inclusive he will solve half or more of all the problems.
Determine the index of day when Polycarp will celebrate the equator.
The first line contains a single integer nn (1≤n≤2000001≤n≤200000) — the number of days to prepare for the programming contests.
The second line contains a sequence a1,a2,…,ana1,a2,…,an (1≤ai≤100001≤ai≤10000), where aiai equals to the number of problems, which Polycarp will solve on the ii-th day.
Print the index of the day when Polycarp will celebrate the equator.
4
1 3 2 1
2
6
2 2 2 2 2 2
3
In the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve 44out of 77 scheduled problems on four days of the training.
In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (inclusive) he will solve 66out of 1212 scheduled problems on six days of the training.
题意:求一组数据中大于等于和的一半的数的位置在哪
tips:一开始我用的是找的 t>sum/2的位置,然后被hack了,冷静分析了一波
如果输入的数据是 6 1 2 3 1 2 4时
得到的答案是
但是实际上应该是4,因为 ‘/’ 这个是向0取整,所sum/2=6,但是在i=3这个地方时 t=6,所以为了‘/’所产生的误差 就用t*2>sum来判断 就不会产生误差
实际上是一个水题,但是要注意细节
附上代码
#include<bits/stdc++.h>
using namespace std;
const int maxx=;
typedef long long ll;
int a[maxx];
int main()
{
int n;
ll s=;
scanf("%d",&n);
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
s+=a[i];
}
ll t=;
for(int i=;i<=n;i++){
t+=a[i];
if(t*>=s){
printf("%d\n",i);
break;
}
}
return ;
}
Educational Codeforces Round 42 (Rated for Div. 2) A的更多相关文章
- Educational Codeforces Round 42 (Rated for Div. 2) E. Byteland, Berland and Disputed Cities
http://codeforces.com/contest/962/problem/E E. Byteland, Berland and Disputed Cities time limit per ...
- Educational Codeforces Round 42 (Rated for Div. 2) D. Merge Equals
http://codeforces.com/contest/962/problem/D D. Merge Equals time limit per test 2 seconds memory lim ...
- Educational Codeforces Round 42 (Rated for Div. 2)F - Simple Cycles Edges
http://codeforces.com/contest/962/problem/F 求没有被两个及以上的简单环包含的边 解法:双联通求割顶,在bcc中看这是不是一个简单环,是的话把整个bcc的环加 ...
- Educational Codeforces Round 42 (Rated for Div. 2) C
C. Make a Square time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- Educational Codeforces Round 42 (Rated for Div. 2) B
B. Students in Railway Carriage time limit per test 2 seconds memory limit per test 256 megabytes in ...
- D. Merge Equals(from Educational Codeforces Round 42 (Rated for Div. 2))
模拟题,运用强大的stl. #include <iostream> #include <map> #include <algorithm> #include < ...
- Educational Codeforces Round 42 (Rated for Div. 2)
A. Equator(模拟) 找权值的中位数,直接模拟.. 代码写的好丑qwq.. #include<cstdio> #include<cstring> #include< ...
- C Make a Square Educational Codeforces Round 42 (Rated for Div. 2) (暴力枚举,字符串匹配)
C. Make a Square time limit per test2 seconds memory limit per test256 megabytes inputstandard input ...
- D Merge Equals Educational Codeforces Round 42 (Rated for Div. 2) (STL )
D. Merge Equals time limit per test2 seconds memory limit per test256 megabytes inputstandard input ...
随机推荐
- linux连接FreeBSD虚拟机的mysql
前言 本人菜鸟一枚,第一次写博客,不喜误喷. 实验环境 Opensuse15.0(主机).FreeBSD11.1(虚拟机).虚拟机VirtualBox5.2.22.mysql8.0.14 在FreeB ...
- 7-4 python 接口开发(提供mock服务)
1.登录接口开发(数据存在数据库中) 接口开发做mock(模拟功能) tools.py import pymysql def my_db(sql): conn = pymysql.connect(h ...
- Java数据处理
对于形如“(TYPE=SITA##)&&(((CTYP=FPL##)||(CTYP=CHG##)||(CTYP=CNL##)||(CTYP=DLA##)||(CTYP=DL##)||( ...
- 使用cookie登陆知乎
只是想说明一个问题,Cookie可以维持登录状态,有些网页当中,访问之后的cookie里面带有登陆账号,和登陆密码,这样可以使用cookie直接访问网页,如知乎,首先登录知乎,将Headers中的Co ...
- Laravel系列之CMS系统学习 — 角色、权限配置【1】
一.后台Admin模块 后台管理是有管理员的,甚至超级管理员,所以在设计数据表的时候,就会有2个方案,一个方案是共用users数据表,添加is_admin,is_superAdmin字段来进行验证,或 ...
- Android内购订单验证 --- nodejs实现
主代码: function AndroidPlayVerify(inappPurchaseData, inappDataSignature) { let verify = crypto.createV ...
- stark组件(11):组合搜索
效果图: 新增函数和类 Option 获取字段的对象或元组 SearchGroupRow 封装数据,展示到前端 get_search_group 获取组合搜索的字段 get_search_group_ ...
- qt5.10.1编译记录
qt版本更新比较快,不知道选哪个版本合适,故选择一个较新版本的. 平台imx6 + linux4.1.16 + qt5.10.1 采用明远智睿提供的编译器:fsl-imx-fb-g ...
- mybatis中@Param用法
用注解来简化xml配置的时候,@Param注解的作用是给参数命名,参数命名后就能根据名字得到参数值,正确的将参数传入sql语句中 我们先来看Mapper接口中的@Select方法 package Ma ...
- IAR配置ICF到项目的实现方法
以STM8为例: 将项目使用的MCU型号的icf文件拷贝到项目里面,icf一般放在 C:\Program Files\IAR Systems\Embedded Workbench 6.5\stm8\c ...