首页 技术 正文
技术 2022年11月14日
0 收藏 564 点赞 2,458 浏览 1146 个字

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 ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,028
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,518
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,365
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,146
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,780
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,857