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

预处理出每两个相邻的数的差值,那么首先知道是一共取了sum / ((1 + n) * n / 2)次,因为每一次固定要取这么多,所以这个就是操作次数。

然后观察到,每一次操作,都是把dis[]数组的n - 1个减小1,有一个要加上n - 1、最终要变成0

那么问题就是转化成,给定一个数,有两种操作,

第一种是减去1,第二种是加上某一个数,问其在k步后,能否变成0

那么设第一种操作用了x次,第二种操作就是k - x次,那么带入去,能得出一条方程。

dis[i] - x + (k - x) * (n - 1) = 0  (错误了)

不知为何这样错了,很假。

然后题解是设第一种用了k - x次,第二种用了x次。

那么就是dis[i] - (k - x) + x * (n - 1) = 0(能过)

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <assert.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <bitset>
const int maxn = 2e5 + ;
int a[maxn];
vector<int>da;
void work() {
int n;
LL sum = ;
cin >> n;
for (int i = ; i <= n; ++i) {
cin >> a[i];
sum += a[i];
}
LL add = 1LL * n * (n + ) / ;
if (sum % add != ) {
cout << "NO" << endl;
return;
}
for (int i = ; i <= n; ++i) {
da.push_back(a[i] - a[i - ]);
}
da.push_back(a[] - a[n]);
LL k = sum / add;
for (int i = ; i < da.size(); ++i) {
LL t = k - da[i];
// LL t = da[i] + k * (n - 1);
if (t % n != || t < ) {
cout << "NO" << endl;
return;
}
}
cout << "YES" << endl;
} int main() {
#ifdef local
freopen("data.txt", "r", stdin);
// freopen("data.txt", "w", stdout);
#endif
work();
return ;
}

最新文章

  1. 大量无线键盘存在KeySniffer漏洞-可嗅探用户输入的内容
  2. mysql 多表连接
  3. extjs form.load()加载服务端数据
  4. Jfinal----Handler之责任链设计模式
  5. C# list使用方法
  6. 【MFC初学】
  7. 学习篇之String()
  8. Unity 游戏框架搭建 (二) 单例的模板
  9. 前端之基础css
  10. Go笔记-流程控制
  11. sequence测试中的使用
  12. Codeforces 382 D Permutations
  13. [UE4]加入音效
  14. 【第十九章】 springboot + hystrix(1)
  15. python里实现DSL
  16. 获取URL中的链接(可中文也可英文)
  17. Vue.js2 + Laravel5 采用 CORS 方式解决 AJAX 跨域的问题
  18. js splice方法
  19. poj 1961 Period
  20. docker 关于volumns的总结(转)

热门文章

  1. 奥斯卡&amp;#183;王尔德十大经典语录
  2. AsyncSocket中tag參数的用处
  3. 关于Python中正则表达式的反斜杠问题
  4. linux远程管理工具:putty
  5. ARGB,RGB颜色值表示
  6. WAMP的端口修改
  7. is和==的区别,小数据池,编码
  8. python iterable 和list、dictionary的区别和联系
  9. 聚合类新闻client初体验
  10. 不常见使用的css