题目直通车: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. iOS笔记053- Quartz2D-练习

    1.水印处理 给图片添加文字.图片水印 // 水印处理 - (void)shuiyin { // 水印处理 UIImage *image  = [UIImage imageNamed:@"4 ...

  2. eclipse集成python(Pydev插件安装)

    1.下载PyDev的压缩包,解压后会有features和plugins两个文件夹,将两个文件夹的内容拷贝到eclipse对应的文件夹中,重新启动eclipse 2.配置python 2.1打开ecli ...

  3. [shell]查找网段内可用IP地址

    #网段可用IP地址 #!/bin/sh ip= " ]; do .$ip -c |grep -q "ttl=" && echo "10.86.8 ...

  4. C#向上转型与向下转型(转)

    原文地址:https://blog.csdn.net/wangqingbo0829/article/details/48474173 向上转型:将子类对象转为父类对象.此处父类对象可以是接口. 向下转 ...

  5. Actiivity 生命周期

    Actiivity 生命周期,如下图所示: onCreate onStart (onRestarted) onResume onPaused(to onResume(User navigates to ...

  6. Metaspolit

    Metaspolit介绍 Metasploit是一款开源的安全漏洞检测工具,安全工作人员常用 Metasploit工具来检测系统的安全性.Metasploit Framework (MSF) 在200 ...

  7. 微信公众号开发java框架:wx4j(入门篇)

    导航 入门 http://www.cnblogs.com/2333/p/6617819.html WxServlet介绍 MaterialUtils 素材工具类使用说明 http://www.cnbl ...

  8. C#读取xml文件写入到TreeView中

    开发过程中我们会遇到一些读取xml文件的时候,下面是我学习的整理. 用XmlDocument读取加载 XmlDocument doc = new XmlDocument(); doc.Load(&qu ...

  9. sqlalchemy presto 时间比较

    大数据统计时,需要计算开仓订单减掉经纪商时间差,等于n 小时 或 星期几的订单. presto sql语句如下: select sum(profit) from t_table where open_ ...

  10. [转]mysql联合索引

    mysql联合索引   命名规则:表名_字段名1.需要加索引的字段,要在where条件中2.数据量少的字段不需要加索引3.如果where条件中是OR关系,加索引不起作用4.符合最左原则 https:/ ...