题目直通车:http://codeforces.com/problemset/problem/1028/E

解法:设原数组为ar[],求ar中的最大值的下标ins,依次向前遍历一遍,每一个答案值都为前一个答案值+余值(ar[i]),这样可以达到题意的要求

输出为NO的情况就是所有ar元素相等且不为0

麻烦的地方在于0值得特判,代码中有说明

#include<iostream>
#include<cstdio>
#include<cmath>
#include<queue>
#include<vector>
#include<string.h>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<fstream>
#include<cstdlib>
#include<ctime>
#include<list>
#include<climits>
#include<bitset>
using namespace std;
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fopen freopen("input.in", "r", stdin);freopen("output.in", "w", stdout);
#define left asfdasdasdfasdfsdfasfsdfasfdas1
#define tan asfdasdasdfasdfasfdfasfsdfasfdas
typedef long long ll;
typedef unsigned int un;
const int desll[][]={{,},{,-},{,},{-,}};
const ll mod=1e9+;
const int maxn=4e5+;
const int maxm=1e6+;
const double eps=1e-;
int m,n;
int ar[maxn];
ll ansl[maxn];
int main()
{
scanf("%d",&n);
for(int i=;i<n;i++)scanf("%d",&ar[i]);
int ins=,mx=;
for(int i=;i<n;i++){
if(mx<ar[i]){
mx=ar[i];
ins=i;
}
}
int l=,r=n-;
while(l<n && ar[l]==mx)l++;
while(r>= && ar[r]==mx)r--;
if(l==n){
if(ar[]>){
printf("NO\n");
return ;
}
}
if(l> && r<n-){
ins=r+;
}
int i=ins;
ins=;
ansl[i]=ar[i];
if(mx== && l==n)ansl[i]=;
while(++ins<n){
int j;
if(i==)j=n-;
else j=i-;
ansl[j]=ansl[i]+ar[j];
if(ar[j]== && ansl[j]==mx)ansl[j]*=;//特殊处理0
i=j;
}
if((ar[i]== && ansl[i]==ansl[(i+)%n]) || ansl[i]%ansl[(i+)%n]==ar[i]){//前一部分特殊处理0
printf("YES\n");
for(int i=;i<n;i++){
printf("%I64d%c",ansl[i],i!=n-?' ':'\n');
}
}
else printf("NO\n"); return ;
}

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

  1. Codeforces 1028E Restore Array 构造

    我发现我构造题真的不会写, 想了好久才想出来.. 我们先把n = 2, 所有数字相等, 所有数字等于0的都特判掉. 找到一个b[ i ] > b[ i - 1 ]的位置把它移到最后一个位置, 并 ...

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

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

  3. Codeforces 1077C Good Array 坑 C

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

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

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

  5. codeforces 407C Curious Array

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

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

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

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

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

  8. codeforces 86D : Powerful array

    Description An array of positive integers a1, a2, ..., an is given. Let us consider its arbitrary su ...

  9. Codeforces 660A. Co-prime Array 最大公约数

    A. Co-prime Array time limit per test 1 second memory limit per test 256 megabytes input standard in ...

随机推荐

  1. python3知识点之---------列表的介绍

    1.列表是什么? 它是由一系列特定顺序排序的元素组成.元素可以表示一切任何的事物,元素之间可以没有任何关系.列表用方括号[ ] 表示,元素之间由逗号隔开.   例如表示一系列数字的列表:  numbe ...

  2. Python全栈工程师 (类变量、方法、继承、覆盖)

    ParisGabriel                每天坚持手写  一天一篇  决定坚持几年 为了梦想为了信仰    开局一张图 Python人工智能从入门到精通 补充: 实例方法都是操作实例对象 ...

  3. ubantu 系统常见问题

    1 搜狗输入法错误: 删除home路径下的 .config/SouGouP...整个文件夹并重启 2  ubantu系统更新:sudo apt-get update  获取最近更新的软件包列表     ...

  4. 系统编程--高级IO

    1.非阻塞I/O 非阻塞I/O使我们可以调用不会永远阻塞的I/O操作,例如open,read和write.如果这种操作不能完成,则立即出错返回,表示该操作如继续执行将继续阻塞下去.对于一个给定的描述符 ...

  5. 【python】用python爬取中科院院士简介信息

    018/07/09 23:43 项目名称:爬取中科院871个院士的简介信息 1.爬取目的:中科院871个院士的简介信息 2.爬取最终结果: 3.具体代码如下: import re # 不用安装(注意! ...

  6. ocrosoft Contest1316 - 信奥编程之路~~~~~第三关 问题 P: 【数组】1234方阵(phalanx)

    http://acm.ocrosoft.com/problem.php?cid=1316&pid=15 题目描述 编程打印如下规律的n*n方阵.输入n,按规律输出方阵. 方阵规律如下图:使左对 ...

  7. C# 在子窗体调用父窗体的值(转)

    1.在父窗体中 public delegate void SetVisiableHandler();//定义委托类型 注意此委托定义在namespace下一级,在form类外 private void ...

  8. [NOI2015][bzoj4197] 寿司晚宴 [状压dp+质因数]

    题面 传送门 思路 首先,要让两个人选的数字全部互质,那么有一个显然的充要条件:甲选的数字的质因数集合和乙选的数字的质因数集合没有交集 30pt 这种情况下n<=30,也就是说可用的质数只有10 ...

  9. JZOJ 5305 C先生

    题意: 有一个n个点,m条边的图,没有重边.自环,且每一条边最多属于一个环路. 给出q组询问,每次询问u,v两点间的路径有多少种可能. 思路: 先看下方样例说明: 由样例说明可以得知,路径上每经过一个 ...

  10. [poj] 2318 TOYS || 判断点在多边形内

    原题 给出一个矩形玩具箱和其中隔板的位置,求每个玩具在第几个隔间内(保证没有在线上的玩具) 将玩具按x轴排序,记录当前隔板的编号,每次判断是否需要右移(左移)隔板(因为是有序的,所以移动次数左右不厚超 ...