B-Boxes
http://agc010.contest.atcoder.jp/tasks/agc010_b
Problem Statement
There are N boxes arranged in a circle. The i-th box contains Ai stones.
Determine whether it is possible to remove all the stones from the boxes by repeatedly performing the following operation:
- Select one box. Let the box be the i-th box. Then, for each j from 1 through N, remove exactly j stones from the (i+j)-th box. Here, the (N+k)-th box is identified with the k-th box.
Note that the operation cannot be performed if there is a box that does not contain enough number of stones to be removed.
Constraints
- 1≦N≦105
- 1≦Ai≦109
Input
The input is given from Standard Input in the following format:
N
A1 A2 … AN
Output
If it is possible to remove all the stones from the boxes, print YES
. Otherwise, print NO
.
Sample Input 1
5
4 5 1 2 3
Sample Output 1
YES
All the stones can be removed in one operation by selecting the second box.
Sample Input 2
5
6 9 12 10 8
Sample Output 2
YES
Sample Input 3
4
1 2 3 1
Sample Output 3
NO
大致意思是说,假设初始化N个数字为0,选取某一个位置,分别增加1到N(如果到达数组末尾就从头开始)。
比如:
0 0 0(选择第二个位置开始)
3 1 2(选择第三个位置开始)
5 4 3(选择第 X 个位置开始)
.......
给出N个数字,看看是不是由以上操作得到的,是的话输出YES,不是输出NO;
对于数据,记录其和,则K=(n*(n+1))/2为操作次数,另d[i]=a[i]-a[i-1];必定有一个的d[i]=n-1;剩下的为1;
且有d[i]-(k-x)+(n-1)*x=0或k-d[i]=nx(x为相对于的d[i]来说异常操作的数),所以,一定有k-d[i]>=0 && (k-d[i])%n==0,
也可以得到(k-d[i])/n的和为k,由此可解题。
#include<iostream>
using namespace std;
const int mod=1e5+;
long long a[mod],b[mod];
int main()
{
long long n,i,sum=,count=,k;
cin>>n;
for(i=;i<=n;i++)
{
cin>>a[i];
b[i]=a[i]-a[i-];
sum+=a[i];
}
b[]=a[]-a[n];
if(sum%(n*(n+)/))//如果k不为整数,直接输出NO
{
cout<<"NO"<<endl;
return ;
}
k=sum/(n*(n+)/);
for(i=;i<=n;i++)
{
if((k-b[i]<) || (k-b[i])%n)
{
cout<<"NO"<<endl;
return ;
}
else count+=(k-b[i])/n;
}
if(count!=k) cout<<"NO"<<endl;
else cout<<"YES"<<endl;
return ;
}
B-Boxes的更多相关文章
- Fedora 24 Gnome Boxes 无法ping通网络
安装Fedora 24在试用虚拟机时发现无法ping通外网. 我傻傻地以为是软件问题. 问题描述: 尝试ping程序来测试网络连通性: (我之前也是ping百度,后来在为了少打字百度了一些比较短的域名 ...
- Problem B Boxes in a Line
省赛B题....手写链表..其实很简单的.... 比赛时太急了,各种手残....没搞出来....要不然就有金了...注:对相邻的元素需要特判..... Problem B Boxes in a Li ...
- Codeforces Round #229 (Div. 2) C. Inna and Candy Boxes 树状数组s
C. Inna and Candy Boxes Inna loves sweets very much. She has n closed present boxes lines up in a ...
- boxes
boxes [英][bɒksɪz][美][bɑ:ksɪz] n.盒( box的名词复数 ); 一盒; 电视; 小亭; v.把…装入盒[箱,匣]中( box的第三人称单数 ); 拳击; 以上结果来自 ...
- Brute Force - B. Candy Boxes ( Codeforces Round #278 (Div. 2)
B. Candy Boxes Problem's Link: http://codeforces.com/contest/488/problem/B Mean: T题目意思很简单,不解释. ana ...
- UVa 103 - Stacking Boxes(dp求解)
题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&pa ...
- [CareerCup] 9.10 Stack Boxes 垒箱子问题
9.10 You have a stack of n boxes, with widths w., heights hir and depths drThe boxes cannot be rotat ...
- 北京网络赛G BOXES 状态压缩+有序BFS+高维数组判重
#include <bits/stdc++.h> using namespace std; ]; ][]; ][][]; ][][][]; ][][][][]; ][][][][][]; ...
- 找规律 SGU 126 Boxes
题目地址:http://acm.sgu.ru/problem.php?contest=0&problem=126 /* 找规律,智商不够,看了题解 详细解释:http://blog.csdn. ...
- poj 1475 || zoj 249 Pushing Boxes
http://poj.org/problem?id=1475 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=249 Pushin ...
随机推荐
- ubuntu16.04安装opencl
参考链接:https://www.jianshu.com/p/ad808584ce26 安装OpenCL OpenCL是一系列库和头文件,需要根据硬件安装对应的SDK,也就是说,如果希望使用Intel ...
- SpringMVC+Spring+Hibernate框架整合原理,作用及使用方法
转自:https://blog.csdn.net/bieleyang/article/details/77862042 SSM框架是spring MVC ,spring和mybatis框架的整合,是标 ...
- xBIM 高级01 IFC多模型合并
系列目录 [已更新最新开发文章,点击查看详细] 多模型合并可以实现以下功能: 覆盖多个模型以表现得像一个模型 统一访问数据,就像它是单个模型一样 只读.要修改模型的内容,您必须使用特定模型 不 ...
- MyBatis数据持久化(五)数据源配置优化
在前面的教程中,我们把数据库的驱动.用户名.密码等配置项全部写在 SqlMapConfig.xml中: <dataSource type="POOLED"> <p ...
- Codeforces 987A. Infinity Gauntlet(手速题,map存一下输出即可)
解法: 1.先将对应的字符串存入map. 2.然后将输入的串的second置为空. 3.输出6-n,输出map中的非空串. 代码: #include <bits/stdc++.h> usi ...
- 使用3ds Max制作卡通狗教程
使用软件::3ds Max 软件下载:http://www.xy3dsmax.com/xiazai.html 全教程完,学完记得交作业.如果本教程对您有所帮助,请推荐给你的朋友. 全教程完,学完记得交 ...
- 详解JavaScript中的原型和继承-转自颜海镜大大
本文将会介绍面向对象,继承,原型等相关知识,涉及的知识点如下: 面向对象与继承 CEOC OLOO 臃肿的对象 原型与原型链 修改原型的方式 面向对象与继承 最近学习了下python,还写了篇博文&l ...
- CSS3新增的属性有哪些:
CSS 用于控制网页的样式和布局. CSS3 是最新的 CSS 标准. CSS3新增了很多的属性,下面一起来分析一下新增的一些属性: 1.CSS3边框: border-radius:CSS3圆角边框. ...
- LAMP 建立 Wordpress 站点 Linux Apache MariaDB PHP
使用LAMP建立Wordpress, 要求如下: 准备工作: VMware 14 CentOS 7.4 最小化 安装镜像 Wordpress 安装包, 下载 预热: 使用VMware新建4台虚拟机, ...
- python_模块学习
'''import sysprint(sys.path) #打印环境变量 #运行结果为:['D:\\PyCharm Community Edition 2018.2.2\\NewYear\\untit ...