Codeforces 1028E. Restore Array
题目直通车: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的更多相关文章
- Codeforces 1028E Restore Array 构造
我发现我构造题真的不会写, 想了好久才想出来.. 我们先把n = 2, 所有数字相等, 所有数字等于0的都特判掉. 找到一个b[ i ] > b[ i - 1 ]的位置把它移到最后一个位置, 并 ...
- 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} ...
- codeforces 86D : Powerful array
Description An array of positive integers a1, a2, ..., an is given. Let us consider its arbitrary su ...
- Codeforces 660A. Co-prime Array 最大公约数
A. Co-prime Array time limit per test 1 second memory limit per test 256 megabytes input standard in ...
随机推荐
- 【Lowest Common Ancestor of a Binary Tree】cpp
题目: Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. Accor ...
- 为什么要内存对齐 Data alignment: Straighten up and fly right
转载于http://blog.csdn.net/lgouc/article/details/8235471 为了速度和正确性,请对齐你的数据. 概述:对于所有直接操作内存的程序员来说,数据对齐都是很重 ...
- typescript语言
百度百科:2013年6月19日,在经历了一个预览版之后微软正式发布了正式版TypeScript 0.9
- 201621123034 《Java程序设计》第6周学习总结
作业06-接口.内部类 1. 本周学习总结 1.1 面向对象学习暂告一段落,请使用思维导图,以封装.继承.多态为核心概念画一张思维导图或相关笔记,对面向对象思想进行一个总结. 注1:关键词与内容不求多 ...
- Nagios 监控系统架设全攻略
Nagios 全名为(Nagios Ain’t Goona Insist on Saintood),最初项目名字是 NetSaint.它是一款免费的开源 IT 基础设施监控系统,其功能强大,灵活性强, ...
- P1270 “访问”美术馆
题目描述 经过数月的精心准备,Peer Brelstet,一个出了名的盗画者,准备开始他的下一个行动.艺术馆的结构,每条走廊要么分叉为两条走廊,要么通向一个展览室.Peer知道每个展室里藏画的数量,并 ...
- 在HTML网页上打印需要的内容
首先在head里面加入下面一段js代码: function preview(oper) { if (oper < 10) { bdhtml = window.document.body.inne ...
- Codeforces:Good Bye 2018(题解)
Good Bye 2018! 题目链接:https://codeforces.com/contest/1091 A. New Year and the Christmas Ornament 题意: 给 ...
- XML格式化及解析
XML格式化工具:notepad++ 下载地址 http://rj.baidu.com/soft/detail/13478.html?ald 一个教程地址:http://jingyan.ba ...
- ubuntu xampp
1.下载:首先通过wget下载 xampp linux 1.7.3a版本,地址为http://sourceforge.net/projects/xampp/files/XAMPP%20Linux/ ...