AtCoder 2303 Boxes

http://www.elijahqi.win/archives/1357

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

B - Boxes
Time limit時間制限 : 2sec / Memory limitメモリ制限 : 256MB

配点 : 500 点

問題文
N 個の箱が円環状に並んでおり、i 番目の箱には Ai 個の石が入っています。

以下の操作を繰り返して、全ての石を取り除くことができるか判定してください。

箱を一か所選ぶ。それを i 番目としたとき、1 から N の各 j に対して、i+j 番目の箱から石をちょうど j 個取り除く。
ただし、N+k 番目と表される箱は k 番目の箱と同一視するものとする。
各操作において、取り除きたい個数の石がない箱があるときは、その操作を行えないことに注意してください。

制約
1≦N≦105
1≦Ai≦109
入力
入力は以下の形式で標準入力から与えられる。

N
A1 A2 … AN
出力
全ての石を取り除くことができるなら YES を、そうでないなら NO を出力せよ。

入力例 1
Copy
5
4 5 1 2 3
出力例 1
Copy
YES
最初に箱 2 を選ぶことで、一回の操作ですべての石を回収できます。

入力例 2
Copy
5
6 9 12 10 8
出力例 2
Copy
YES
入力例 3
Copy
4
1 2 3 1
出力例 3
Copy
NO
Score : 500 points

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
Copy
5
4 5 1 2 3
Sample Output 1
Copy
YES
All the stones can be removed in one operation by selecting the second box.

Sample Input 2
Copy
5
6 9 12 10 8
Sample Output 2
Copy
YES
Sample Input 3
Copy
4
1 2 3 1
Sample Output 3
Copy
NO

强啊 很妙啊zhx大佬和jpy大佬当场秒了这题 这题这么难 我哪会啊

因为是一个排列所以我们应该来研究他们的差有什么关系 我们可以知道每个数之间差的形成都是由于 排列而形成的 有可能我是一头一尾 那么差就是-(n-1) 其他则为+1 那么我不妨把第一位在末尾重新加一下 然后算出他们的差 通过这个差我们可以解一个一元一次方程 分别求出每个位置有多少个排列是从这里开始的 只要这个排列数不<0或者不是整数那么就可能是答案 注意1的时候要提前特判输出yes

#include<cstdio>
#define N 110000
inline char gc(){
    static char now[1<<16],*T,*S;
    if (T==S){T=(S=now)+fread(now,1,1<<16,stdin);if (T==S) return EOF;}
    return *S++;
}
inline int read(){
    int x=0;char ch=gc();
    while (ch<'0'||ch>'9') ch=gc();
    while (ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=gc();}
    return x;
}
int n,a[N],differ[N];
int main(){
    freopen("box.in","r",stdin);
    n=read();long long sum=0;long long sum1=0;
    if (n==1){printf("YES");return 0;}
    sum1=(long long)n*(n+1)>>1;
    for (int i=1;i<=n;++i) a[i]=read(),sum+=a[i];a[n+1]=a[1];
    for (int i=1;i<=n;++i) differ[i]=a[i+1]-a[i];int k=sum/sum1;
    if (sum%sum1){printf("NO");return 0;}
    for (int i=1;i<=n;++i){
        double x=(differ[i]-k)/(-1.0*n);
        if (x<0){printf("NO");return 0;}
        int xx=x;if (xx!=x){printf("NO");return 0;}
    }
    printf("YES");
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值