Codeforces 1028E Restore Array 构造
我发现我构造题真的不会写, 想了好久才想出来。。
我们先把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 构造的更多相关文章
- Codeforces 1028E. Restore Array
题目直通车:http://codeforces.com/problemset/problem/1028/E 解法:设原数组为ar[],求ar中的最大值的下标ins,依次向前遍历一遍,每一个答案值都为前 ...
- CF1028E Restore Array 构造
正解:构造 解题报告: 传送门! 是的灵巧还在写构造,,,不知道484我做题太慢的缘故我感觉我做了好久的构造了然而一半的题目都没做完QAQ 要哭出来了QAQ 然后说下这题的解法,开始花了这——么的时间 ...
- CodeForces 404C Restore Graph (构造)
题意:让人构造一个图,满足每个结点边的数目不超过 k,然后给出每个结点到某个结点的最短距离. 析:很容易看出来如果可能的话,树是一定满足条件的,只要从头开始构造这棵树就好,中途超了int...找了好久 ...
- Codeforces 482B Interesting Array(线段树)
题目链接:Codeforces 482B Interesting Array 题目大意:给定一个长度为N的数组,如今有M个限制,每一个限制有l,r,q,表示从a[l]~a[r]取且后的数一定为q,问是 ...
- Codeforces 1077C Good Array 坑 C
Codeforces 1077C Good Array https://vjudge.net/problem/CodeForces-1077C 题目: Let's call an array good ...
- codeforces 482B. Interesting Array【线段树区间更新】
题目:codeforces 482B. Interesting Array 题意:给你一个值n和m中操作,每种操作就是三个数 l ,r,val. 就是区间l---r上的与的值为val,最后问你原来的数 ...
- codeforces 407C Curious Array
codeforces 407C Curious Array UPD: 我觉得这个做法比较好理解啊 参考题解:https://www.cnblogs.com/ChopsticksAN/p/4908377 ...
- codeforces 797 E. Array Queries【dp,暴力】
题目链接:codeforces 797 E. Array Queries 题意:给你一个长度为n的数组a,和q个询问,每次询问为(p,k),相应的把p转换为p+a[p]+k,直到p > n为 ...
- [Codeforces 1208D]Restore Permutation (树状数组)
[Codeforces 1208D]Restore Permutation (树状数组) 题面 有一个长度为n的排列a.对于每个元素i,\(s_i\)表示\(\sum_{j=1,a_j<a_i} ...
随机推荐
- 用Python建设企业认证和权限控制平台
目前大家对Python的了解更多来源是数据分析.AI.运维工具开发,在行业中使用Python进行web开发,同样也是非常受欢迎的,例如:FaceBook,豆瓣,知乎,饿了么等等,本文主要是介绍是利用P ...
- 【BZOJ1560】[JSOI2009]火星藏宝图(贪心,动态规划)
[BZOJ1560][JSOI2009]火星藏宝图(贪心,动态规划) 题面 BZOJ 洛谷 题解 既然所有的位置的权值都大于\(0\),那么就可以直接贪心,按照行为第一关键字,列为第二关键字,来转移. ...
- mes平台Action类模版
Connection conn = null; PreparedStatement pst = null; ResultSet rs = null; @Override public String e ...
- o2o优惠券使用预测
前沿: 这是天池的一个新人实战塞题目,原址 https://tianchi.aliyun.com/getStart/information.htm?spm=5176.100067.5678.2.e13 ...
- linux BASH shell下设置字体及背景颜色
BASH shell下设置字体及背景颜色 echo -e "\e[31mtest\e[41m" \e[30m 将字符的显示颜色改为黑色 \e[31m 将字符的显示颜色改为红色 \e ...
- Java与groovy混编 —— 一种兼顾接口清晰和实现敏捷的开发方式
有大量平均水平左右的"工人"可被选择.参与进来 -- 这意味着好招人 有成熟的.大量的程序库可供选择 -- 这意味着大多数项目都是既有程序库的拼装,标准化程度高而定制化场景少 开发 ...
- LFS、BLFS、ALFS、HLFS的区别
转自:http://www.ha97.com/3927.html Linux From Scratch (LFS) 及其后代代表一种新方法,向用户揭示 Linux 操作系统是如何工作的.LFS 基于这 ...
- Codeforces 543 B. World Tour
http://codeforces.com/problemset/problem/543/B 题意: 给定一张边权均为1的无向图. 问至多可以删除多少边,使得s1到t1的最短路不超过l1,s2到t2的 ...
- 流媒体技术学习笔记之(三)Nginx-Rtmp-Module统计某频道在线观看流的客户数
获得订阅者人数,可以方便地显示观看流的客户数. 查看已经安装好的模块 /usr/local/nginx/sbin/nginx -V 安装从源编译Nginx和Nginx-RTMP所需的工具 sudo a ...
- ie6下的line-height属性
line-height这个属性是被ie6所支持的. 当是当一个父级元素内的子元素,包含了文字,且文字和img,input,label,span这些内联元素连接在一起的时候,你对父级元素设置line-h ...