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 A2AN

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的更多相关文章

  1. Fedora 24 Gnome Boxes 无法ping通网络

    安装Fedora 24在试用虚拟机时发现无法ping通外网. 我傻傻地以为是软件问题. 问题描述: 尝试ping程序来测试网络连通性: (我之前也是ping百度,后来在为了少打字百度了一些比较短的域名 ...

  2. Problem B Boxes in a Line

     省赛B题....手写链表..其实很简单的.... 比赛时太急了,各种手残....没搞出来....要不然就有金了...注:对相邻的元素需要特判..... Problem B Boxes in a Li ...

  3. 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 ...

  4. boxes

    boxes [英][bɒksɪz][美][bɑ:ksɪz] n.盒( box的名词复数 ); 一盒; 电视; 小亭; v.把…装入盒[箱,匣]中( box的第三人称单数 ); 拳击;   以上结果来自 ...

  5. 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 ...

  6. UVa 103 - Stacking Boxes(dp求解)

    题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&pa ...

  7. [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 ...

  8. 北京网络赛G BOXES 状态压缩+有序BFS+高维数组判重

    #include <bits/stdc++.h> using namespace std; ]; ][]; ][][]; ][][][]; ][][][][]; ][][][][][]; ...

  9. 找规律 SGU 126 Boxes

    题目地址:http://acm.sgu.ru/problem.php?contest=0&problem=126 /* 找规律,智商不够,看了题解 详细解释:http://blog.csdn. ...

  10. poj 1475 || zoj 249 Pushing Boxes

    http://poj.org/problem?id=1475 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=249 Pushin ...

随机推荐

  1. 343D/Codeforces Round #200 (Div. 1) D. Water Tree dfs序+数据结构

    D. Water Tree   Mad scientist Mike has constructed a rooted tree, which consists of n vertices. Each ...

  2. zzulioj--1708--01串也疯狂之光棍也有伴(dp)

    1708: 01串也疯狂之光棍也有伴 Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 199  Solved: 50 SubmitStatusWeb B ...

  3. Opencv Mat矩阵中data、size、depth、elemSize、step等属性的理解

    data: uchar类型的指针,指向Mat数据矩阵的首地址.可以理解为标示一个房屋的门牌号: dims: Mat矩阵的维度,若Mat是一个二维矩阵,则dims=2,三维则dims=3,大多数情况下处 ...

  4. sas与mysql连接方法

    2012年8月11日 sas 9.1.3 版本 与mysql 连接 测试,可以与数据库连接1  通过odbc 直接连通 pass through connect to odbc create tabl ...

  5. Java基础——protected访问修饰符探讨

    Java基础——protected访问修饰符探讨 根据官方说法:(如图) protected修饰符是可以修饰其他包中的子孙类的,但是我做了个实验,结果发现了一个有趣的现象! 具体请往下看: packa ...

  6. (转载)10个实用的但偏执的Java编程技术

    10个实用的但偏执的Java编程技术 在沉浸于编码一段时间以后(比如说我已经投入近20年左右的时间在程序上了),你会渐渐对这些东西习以为常.因为,你知道的…… 作者:小峰来源:码农网|2015-09- ...

  7. fastdfs+nginx的安装部署

    原理图: fastdfs适用场景: fastdfs特别适合海量 中小文件(建议范围:4KB< file_size <500MB)为载体的在线服务. 安装系统介绍: CentOS6.6 安装 ...

  8. angular踩坑记录

    ng-repeat和ng-click同时使用的时候,注意不能直接在ng-click当中写代码,必须在当前$scope中绑定一个事件,转为调用该事件.否则会出现意想不到的情况.具体原因点击这里. 使用自 ...

  9. 使用了未经检查或不安全的操作。有关详细信息, 请使用 -Xlint:unchecked 重新编译。

    警告信息如下:

  10. HDU-3746 Cyclic Nacklace 字符串匹配 KMP算法 求最小循环节

    题目链接:https://cn.vjudge.net/problem/HDU-3746 题意 给一串珠子,我们可以在珠子的最右端或最左端加一些珠子 问做一条包含循环珠子的项链,最少还需要多少珠子 思路 ...