我发现我构造题真的不会写, 想了好久才想出来。。

我们先把n = 2, 所有数字相等, 所有数字等于0的都特判掉。

找到一个b[ i ] > b[ i - 1 ]的位置把它移到最后一个位置, 并且使其a[ i ] = b[ i ]然后从后往前构造。

#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ull unsigned long long using namespace std; const int N = 1e6 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ;
const double eps = 1e-;
const double PI = acos(-); int n, who = -, id[N];
LL a[N], b[N];
bool flag;
int main() {
scanf("%d", &n);
for(int i = ; i < n; i++) {
scanf("%lld", &b[i]);
flag |= b[i];
}
for(int i = ; i < n; i++) {
if(b[(i-+n)%n] < b[i]) who = i;
}
if(!flag) {
puts("YES");
for(int i = ; i < n; i++) printf("1 ");
puts("");
} else if(n == ) {
if(a[] == a[]) puts("NO");
else {
puts("YES");
if(a[] > a[]) printf("%lld %lld\n", a[], a[] + a[]);
else printf("%lld %lld\n", a[] + a[], a[]);
}
} else {
if(who == -) return puts("NO"), ;
int now = , cur = (who + ) % n;
for(int i = ; i <= n; i++) {
id[now++] = cur;
cur = (cur + ) % n;
}
a[id[n - ]] = b[id[n - ]];
for(int i = n - ; i >= ; i--) {
LL low = b[id[(i - + n) % n]] + ;
LL mo = a[id[i + ]];
a[id[i]] = low + (((b[id[i]] % mo) - (low % mo)) % mo + mo) % mo;
}
puts("YES");
for(int i = ; i < n; i++) printf("%lld ", a[i]);
puts("");
}
return ;
} /*
*/

Codeforces 1028E Restore Array 构造的更多相关文章

  1. Codeforces 1028E. Restore Array

    题目直通车:http://codeforces.com/problemset/problem/1028/E 解法:设原数组为ar[],求ar中的最大值的下标ins,依次向前遍历一遍,每一个答案值都为前 ...

  2. CF1028E Restore Array 构造

    正解:构造 解题报告: 传送门! 是的灵巧还在写构造,,,不知道484我做题太慢的缘故我感觉我做了好久的构造了然而一半的题目都没做完QAQ 要哭出来了QAQ 然后说下这题的解法,开始花了这——么的时间 ...

  3. CodeForces 404C Restore Graph (构造)

    题意:让人构造一个图,满足每个结点边的数目不超过 k,然后给出每个结点到某个结点的最短距离. 析:很容易看出来如果可能的话,树是一定满足条件的,只要从头开始构造这棵树就好,中途超了int...找了好久 ...

  4. Codeforces 482B Interesting Array(线段树)

    题目链接:Codeforces 482B Interesting Array 题目大意:给定一个长度为N的数组,如今有M个限制,每一个限制有l,r,q,表示从a[l]~a[r]取且后的数一定为q,问是 ...

  5. Codeforces 1077C Good Array 坑 C

    Codeforces 1077C Good Array https://vjudge.net/problem/CodeForces-1077C 题目: Let's call an array good ...

  6. codeforces 482B. Interesting Array【线段树区间更新】

    题目:codeforces 482B. Interesting Array 题意:给你一个值n和m中操作,每种操作就是三个数 l ,r,val. 就是区间l---r上的与的值为val,最后问你原来的数 ...

  7. codeforces 407C Curious Array

    codeforces 407C Curious Array UPD: 我觉得这个做法比较好理解啊 参考题解:https://www.cnblogs.com/ChopsticksAN/p/4908377 ...

  8. codeforces 797 E. Array Queries【dp,暴力】

    题目链接:codeforces 797 E. Array Queries   题意:给你一个长度为n的数组a,和q个询问,每次询问为(p,k),相应的把p转换为p+a[p]+k,直到p > n为 ...

  9. [Codeforces 1208D]Restore Permutation (树状数组)

    [Codeforces 1208D]Restore Permutation (树状数组) 题面 有一个长度为n的排列a.对于每个元素i,\(s_i\)表示\(\sum_{j=1,a_j<a_i} ...

随机推荐

  1. 【Revit API】创建共享参数

    话不多说,直接上代码 var app = doc.Application; app.SharedParametersFilename = sharedParamFilePath; Definition ...

  2. 【bzoj4009】 HNOI2015—接水果

    http://www.lydsy.com/JudgeOnline/problem.php?id=4009 (题目链接) 题意 给出一颗无根树.有一些路径记为$P_i$,这些路径有两个端点和一个权值$W ...

  3. 基于Maven构建的Spring+Mybatis项目

    项目的目录结构: 1.基于Maven构建Web项目 参考:基于Maven构建Web项目 2.导入项目依赖 Spring 核心容器(Beans.Core.Context.Context support. ...

  4. Stanford机器学习笔记-9. 聚类(K-means算法)

    9. Clustering Content 9. Clustering 9.1 Supervised Learning and Unsupervised Learning 9.2 K-means al ...

  5. 转头条:阿里p7架构师:三年经验应该具备什么样的技能?

    问:工作中,有时候实现一个功能,会去看有没有现成的轮子可用.对于重复造轮子与改造轮子有什么看法? 答:一定会的,其实这也是一个提高技术能力的方法,比如今天想做个日期转换的功能,JDK8有日期的新特性就 ...

  6. nginx 重写URL尾部斜杠

    1. 在URL结尾添加斜杠 在虚拟主机中这么添加一条改写规则: rewrite ^(.*[^/])$ $1/ permanent;或者rewrite ^([/\w-_]*[^/])$ $1/ perm ...

  7. 鸟哥的Linux私房菜——第十六章:学习Shell Scripts

    视频链接:http://www.bilibili.com/video/av10565321/ 1. 什么是 Shell Script       (shell写的脚本)1.1 干嘛学习 shell s ...

  8. hdu 4857 Little Devil I

    http://acm.hdu.edu.cn/showproblem.php?pid=4897 题意:给你一棵树,边的颜色要么为白色,要么为黑色,初始每条边为白色,有三种操作 1.将u-v链上面的所有边 ...

  9. Javascript Image Slider 插件注册机

    Javascript Image Slider 是个不错的轮播插件,兼容 IE 7.0+, Firefox 1.5+, Chrome 1.0+, Safari 3+, Opera 9.0+, Nets ...

  10. iOS编码规范参考

    目录      注释 1.1  多行注释 1.2  单行注释 1.3  函数的注释   命名 2.1  常量的命名 2.2  函数的命名 2.3  变量的命名 2.3.1  成员变量 2.3.2  公 ...