CF549G Happy Line
解题思路
题意大概就是给你个数列,你可以随意交换i,i+1,交换后位于第i+1位的数字+1,位于第i位的数字-1,问最终能否形成一个不下降序列并输出。设初始数列中两个位置x,y最终交换后的位置为u,v(u
代码
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAXN = 200005;
inline int rd(){
int x=0,f=1;char ch=getchar();
while(!isdigit(ch)) {if(ch=='-')f=-1;ch=getchar();}
while(isdigit(ch)) {x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
return x*f;
}
struct Data{
int a,id;
}data[MAXN];
inline bool cmp(Data A,Data B){
return A.a+A.id<B.a+B.id;
}
int n;
int ans[MAXN];
int main(){
n=rd();
for(register int i=1;i<=n;i++) data[i].a=rd(),data[i].id=i;
sort(data+1,data+1+n,cmp);
for(register int i=1;i<=n;i++){
ans[i]=data[i].a+(data[i].id-i);
// cout<<ans[i]<<" ";
if(ans[i]<ans[i-1]) {
puts(":(");
return 0;
}
}
for(register int i=1;i<=n;i++)
printf("%d ",ans[i]);
return 0;
}
CF549G Happy Line的更多相关文章
- ILJMALL project过程中遇到Fragment嵌套问题:IllegalArgumentException: Binary XML file line #23: Duplicate id
出现场景:当点击"分类"再返回"首页"时,发生error退出 BUG描述:Caused by: java.lang.IllegalArgumentExcep ...
- Error on line -1 of document : Premature end of file. Nested exception: Premature end of file.
启动tomcat, 出现, ( 之前都是好好的... ) [lk ] ERROR [08-12 15:10:02] [main] org.springframework.web.context.Con ...
- 关于xml加载提示: Error on line 1 of document : 前言中不允许有内容
我是在java中做的相关测试, 首先粘贴下报错: 读取xml配置文件:xmls\property.xml org.dom4j.DocumentException: Error on line 1 of ...
- Eclipse "Unable to install breakpoint due to missing line number attributes..."
Eclipse 无法找到 该 断点,原因是编译时,字节码改变了,导致eclipse无法读取对应的行了 1.ANT编译的class Eclipse不认,因为eclipse也会编译class.怎么让它们统 ...
- Linix登录报"/etc/profile: line 11: syntax error near unexpected token `$'{\r''"
同事反馈他在一测试服务器(CentOS Linux release 7.2.1511)上修改了/etc/profile文件后,使用source命令不能生效,让我帮忙看看,结果使用SecureCRT一登 ...
- [LeetCode] Line Reflection 直线对称
Given n points on a 2D plane, find if there is such a line parallel to y-axis that reflect the given ...
- [LeetCode] Tenth Line 第十行
How would you print just the 10th line of a file? For example, assume that file.txt has the followin ...
- [LeetCode] Max Points on a Line 共线点个数
Given n points on a 2D plane, find the maximum number of points that lie on the same straight line. ...
- "Installation failed !" in GUI but not in CLI (/usr/bin/winusb: line 78: 18265 Terminated )
"Installation failed !" in GUI but not in CLI (/usr/bin/winusb: line 78: 18265 Terminated ...
随机推荐
- LINUX用户和用户组操作命令
Id Finger Pwck 检查/etc/passwd配置文件内的信息与实际主文件夹是否存在,还可比较/etc/passwd和/etc/shadow的信息是否一致,另外如果/etc/passwd中的 ...
- Android 开发 MediaRecorder音频录制
前言 MediaRecorder类是Android sdk提供的一个专门用于音视频录制,一般利用手机麦克风采集音频和摄像头采集图像.这个类是属于简单的音频录制类,录制音频简单容易但是对音频流的控制也比 ...
- linux centos 恢复 还原 备份 Snapper 快照说明
为什么要使用Snapper快照? 我们可以想像以下场景: 1. 场景一:系统发生意外宕机,工程师无法快速定位问题,业务受到中断,客户十分不满意. 2. 场景二:项目会议上,就是否升级某软件到最新版本, ...
- mysql之备份表和备份数据库
备份表 1.首先创建一个与原来一样的表 create table score2 like score; ###like就是将score表的结构拷贝过来,但是它并不执行数据:也就是说执行完上面的语句之后 ...
- ODOO/OPENERP的网页模块QWEB简述
1.web 模块 注意,OpenERP 模块中 web 部分用到的所有文件必须被放置在模块内的 static 文件夹里.这是强制性的,出于安全考虑. 事实上,我们创建的文件夹 CSS,JS 和 XML ...
- light oj 1098 数学规律
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <math.h> ...
- ireport 无法打开问题
打开时闪退 ,是因为jdk版本过高的原因:https://blog.csdn.net/aust_glj/article/details/52291240 相关软件下载地址: JasperReports ...
- Ubuntu 16.04 安装STS
先将STS下载下来,网址是 https://spring.io/tools/sts/all ,然后将STS压缩包移动或者copy到想要放置的位置,比如, sudo cp spring-tool-sui ...
- python print输出format太好用了
不用担心什么其他的东西了,直接用format: print("{}的Ground,Detected,DetectedRight个数分别为{},{},{},".format(cate ...
- C开发系列-include
include 在include目录下有两个文件,分别为main.m, abc.txt main.m内容 #include <stdio.h> int main(){ #include & ...