B - Boxes

题目连接:

http://agc010.contest.atcoder.jp/tasks/agc010_b

Description

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.

Input

1≦N≦105

1≦Ai≦109

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

5

4 5 1 2 3

Sample Output

YES

Hint

题意

给你n个数,你可以操作任意次,每次操作你可以选择一个数,使得离这个数距离为i的数-i。

问你最后是否能够使得所有数都变成0.

题解:

每次操作会减去1+2+....+n=n(n+1)/2,所以至少sum%(n(n+1)/2)==0

满足这个条件之后,我们发现是一个等差数列递减的,那么我们差分一下,就变成全部减一了。但是!最后一个数和第一个数之间的差值,却增加了(-(n-1)),这个推一下就知道了。

那么差分后的d[i]=a[i+1]-a[i],必须满足d[i] − (k − x) + (n − 1)x = 0,其中k为总共操作次数,x为在这个位置的操作次数,化简后得到k-d[i]=nx,那么我们只需要check(k-d[i]%n==0)就好了。

智商题……

代码

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+7;
int n;
long long a[maxn],b[maxn],sum;
int main()
{
scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%lld",&a[i]),sum+=a[i];
long long t=1ll*n*(n+1)/2;
if(sum%t){
cout<<"NO"<<endl;
return 0;
}
long long cnt = sum/t;
for(int i=0;i<n;i++){
b[i]=(a[(i+1)%n]-a[i]-cnt);
}
bool flag = true;
for(int i=0;i<n;i++){
if(b[i]>0||(-b[i])%n)
flag = false;
}
puts(flag?"YES":"NO");
}

Atcoder Grand Contest 010 B - Boxes 差分的更多相关文章

  1. AtCoder Grand Contest 010

    AtCoder Grand Contest 010 A - Addition 翻译 黑板上写了\(n\)个正整数,每次会擦去两个奇偶性相同的数,然后把他们的和写会到黑板上,问最终能否只剩下一个数. 题 ...

  2. Atcoder Grand Contest 010 C - Cleaning 树贪心(伪)

    C - Cleaning 题目连接: http://agc010.contest.atcoder.jp/tasks/agc010_c Description There is a tree with ...

  3. AtCoder Grand Contest 010 C:Cleaning

    题目传送门:https://agc010.contest.atcoder.jp/tasks/agc010_c 题目翻译 给你一棵树,每个点有个权值,每次操作可以选择两个度数为\(1\)的结点,然后让这 ...

  4. AtCoder Grand Contest 010 F - Tree Game

    题目传送门:https://agc010.contest.atcoder.jp/tasks/agc010_f 题目大意: 给定一棵树,每个节点上有\(a_i\)个石子,某个节点上有一个棋子,两人轮流操 ...

  5. AtCoder Grand Contest 010题解

    传送门 \(A\) 判一下奇数的个数就行了 const int N=1e5+5; int a[N],n,res; int main(){ scanf("%d",&n); f ...

  6. AtCoder Grand Contest 010 D - Decrementing

    题目描述 有n个整数,其中第i个数为Ai.这些数字的gcd为1.两人轮流操作,每次操作把一个大于1的数减1,并把所有数除以所有数的最大公约数,最后无法操作者输,求是否先手必胜. 如果当前的sum为偶数 ...

  7. AtCoder Grand Contest 006

    AtCoder Grand Contest 006 吐槽 这套题要改个名字,叫神仙结论题大赛 A - Prefix and Suffix 翻译 给定两个串,求满足前缀是\(S\),后缀是\(T\),并 ...

  8. Atcoder Grand Contest 036 D - Negative Cycle

    Atcoder Grand Contest 036 D - Negative Cycle 解题思路 在某些情况下,给一张图加或删一些边要使图合法的题目要考虑到最短路的差分约束系统.这一题看似和最短路没 ...

  9. AtCoder Grand Contest 012

    AtCoder Grand Contest 012 A - AtCoder Group Contest 翻译 有\(3n\)个人,每一个人有一个强大值(看我的假翻译),每三个人可以分成一组,一组的强大 ...

随机推荐

  1. git clone错误 fatal: early EOF fatal: index-pack failed

    最后用ssh的方式解决了,不用http https://blog.csdn.net/fastjack/article/details/79757520 用了以下的方法还是不行 今天想 clone 一下 ...

  2. bzoj千题计划192:bzoj1569: [JSOI2008]Blue Mary的职员分配

    http://www.lydsy.com/JudgeOnline/problem.php?id=1569 dp[i][j][a][b] 表示i个职员,发广告状态为j,已有金钱a,声誉b的最少天数 j= ...

  3. 2018年10月14日ICPC南京站参赛总结

    这次比赛消耗掉了我们全部的信心和精力 在热身赛上,总体来说还是比较愉快的,这个时候心态就不对 正赛的时候我们遇到了A题签到题 我一开始是读错了题意了,认为这个题是一个裸的SG函数,而且那么多人秒过 W ...

  4. B-树(B+树) 学习总结

    一,B-树的定义及介绍 为什么会有B-树? 熟悉的树的结构有二叉树查找树或者平衡二叉树……平衡二叉树保证最坏情况下各个操作的时间复杂度为O(logN),但是为了保持平衡,在插入或删除元素时,需要进行旋 ...

  5. 华中邀请赛现场赛F题 Seats

    题目链接:http://acm.whu.edu.cn/land/problem/detail?problem_id=1552 解题报告:题目意思应该很清楚,就是有n个人,分别属于7个班级,然后他们坐成 ...

  6. Anaconda+django写出第一个web app(八)

    今天来实现网站的登入和登出功能. 首先我们需要在urls.py中添加路径,注意此处的路径和在导航栏中设置的文字路径保持一致: from django.urls import path from . i ...

  7. Apache的对象复制详解

    BeanUtils.copyProperties 和 PropertyUtils.copyProperties 两个工具类都是对两个bean之前存在name相同的属性进行处理,无论是源bean或者目标 ...

  8. 如何教会老婆写 Python ?

    什么是code? code就就是一种语言,一种计算机能读懂的语言.计算机是一个傻逼,他理解不了默认两可的任何东西. 比如,你让你老公去买个西瓜,你老公会自己决定去哪里买,买几个,找个搞活动打折的买,总 ...

  9. Mysql锁机制简单了解一下

    历史文章推荐: 可能是最漂亮的Spring事务管理详解 面试中关于Java虚拟机(jvm)的问题看这篇就够了 Java NIO 概览 关于分布式计算的一些概念 一 锁分类(按照锁的粒度分类) Mysq ...

  10. [转]html网页 swf播放器使用代码

    <object id="player" height="240" width="275" classid="CLSID:6B ...