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} ...
随机推荐
- 【题解】 [NOI2009]变换序列 (二分图匹配)
懒得复制,戳我戳我 Solution: 这个题面出的很毒瘤,读懂了其实是个板子题qwq 题面意思:有个\(0\)至\(N-1\)的数列是由另一个数列通过加减得到的,相当于将\(A_i\)变成\(i\) ...
- sql server 小技巧(7) 导出完整sql server 数据库成一个sql文件,包含表结构及数据
1. 右健数据库 –> Tasks –> Generate Scripts 2. 选择所有的表 3. 下一步,选择Advanded, Types of data to script ...
- maven项目添加mysql的链接驱动
Maven项目中添加JDBC驱动 在pom.xml配置文件中添加: <dependency> <groupId>mysql</groupId> <arti ...
- Dom选择器--内容文本操作
一.文本内容操作 内容: <body> <div id="i1"> 学习是我快乐? <a>晚饭吃什么</a> </div> ...
- (转)flask的context机制
本文转自:https://blog.tonyseek.com/post/the-context-mechanism-of-flask/ 作者:无知的 TonySeek 注意:本文仅仅作为个人mark, ...
- 初识python面向对象编程
初识python面向对象编程 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.面向过程的程序设计思想 #!/usr/bin/env python #_*_coding:utf-8 ...
- day63_SpringMVC学习笔记_01
1.JAVAEE体系结构 JAVAEE体系结构图如下所示: 2.什么是springmvc? 什么是mvc? Model1 Model2 SpringMVC是什么? SpringMVC是一个web层mv ...
- oracle用户密码过期!the password has expired
Oracle提示错误消息ORA-28001: the password has expired,是由于Oracle11G的新特性所致, Oracle11G创建用户时缺省密码过期限制是180天(即6个月 ...
- iOS动画1 — UIView动画
iOS动画基础是Core Animation核心动画.Core Animation是iOS平台上负责图形渲染与动画的基础设施.由于核心动画的实现比较复杂,苹果提供了实现简单动画的接口—UIView动画 ...
- j2ee组件简介