STL or 线段树 --- CSU 1555: Inversion Sequence
Inversion Sequence
Problem's Link: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1555
Mean:
给你一个序列a[n],要你按照要求去构造一个序列b。
序列a[i]表示序列b中的i前面有a[i]个数比i大。
转换一下就是:
已知一个连续的序列(1,2,3,4,...),然后告诉了我们这个序列中每个数前面比本身大的个数,根据这些条件将这个序列调整顺序,找到满足条件的序列。
analyse:
STL大法好。直接用vector来insert。
Time complexity: O(nlogn)
Source code:
// Memory Time
// 1347K 0MS
// by : crazyacking
// 2015-03-29-23.24
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<cstdio>
#include<vector>
#include<string>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<iostream>
#include<algorithm>
#define MAXN 1000010
#define LL long long
using namespace std;
const int maxn = ;
int a[maxn];
int ans[maxn];
vector<int>v; int main(){
// freopen("data.in","r",stdin);
int n;
while(scanf("%d",&n)!=EOF){
for(int i=;i<n;i++){
scanf("%d",&a[i]);
}
v.clear();
v.push_back();
int ok=;
for(int i=n-;i>=;i--)
{
if(v.size()<=a[i])
{
ok=;
break;
}
v.insert(v.begin()++a[i],i+);
// for(int j=0;j<v.size();j++)
// printf("%d%c",v[j],j==v.size()-1?'\n':' ');
}
if(ok){
for(int i=;i<=n;i++){
printf("%d%c",v[i],i==n?'\n':' ');
}
}else{
puts("No solution");
}
}
return ;
} /**************************************************************
Problem: 1555
User: crazyacking
Language: C++
Result: Accepted
Time:164 ms
Memory:1576 kb
****************************************************************/
STL or 线段树 --- CSU 1555: Inversion Sequence的更多相关文章
- CSUOJ 1555 Inversion Sequence
1555: Inversion Sequence Time Limit: 2 Sec Memory Limit: 256 MBSubmit: 107 Solved: 34 Description ...
- 1555: Inversion Sequence (通过逆序数复原序列 vector的骚操作!!!)
1555: Inversion Sequence Submit Page Summary Time Limit: 2 Sec Memory Limit: 256 Mb Su ...
- 线段树 区间合并 F - Sequence operation
F - Sequence operation 题解:这个题目不是一个特别难的题目,但是呢,写了好久,首先线段树难敲,其次就是bug难找,最后这个代码都被我改的乱七八糟的了,这个有两个地方要注意一下,一 ...
- 【线段树】HDU 3397 Sequence operation 区间合并
操作 Change operations: 0 a b change all characters into '0's in [a , b] 1 a b change all characters i ...
- csu 1555(线段树经典插队模型-根据逆序数还原序列)
1555: Inversion Sequence Time Limit: 2 Sec Memory Limit: 256 MBSubmit: 469 Solved: 167[Submit][Sta ...
- Inversion Sequence(csu 1555)
Description For sequence i1, i2, i3, … , iN, we set aj to be the number of members in the sequence w ...
- HDU 1394 Minimum Inversion Number(最小逆序数/暴力 线段树 树状数组 归并排序)
题目链接: 传送门 Minimum Inversion Number Time Limit: 1000MS Memory Limit: 32768 K Description The inve ...
- ACM Minimum Inversion Number 解题报告 -线段树
C - Minimum Inversion Number Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d &a ...
- HDU-1394 Minimum Inversion Number 线段树+逆序对
仍旧在练习线段树中..这道题一开始没有完全理解搞了一上午,感到了自己的shabi.. Minimum Inversion Number Time Limit: 2000/1000 MS (Java/O ...
随机推荐
- Fiddler高级技巧 - 映射路径到本地文件夹
适用场景: 你是前端开发人员,要开发一个小模块,需要用到线上的环境(账号.数据.跨域等),但你又没有权限往线上传文件 你是移动测试人员,需要将一组接口的返回结果替换为另一组,最简单的办法就是使用Fid ...
- python字符串格式化方法 format函数的使用
python从2.6开始支持format,新的更加容易读懂的字符串格式化方法, 从原来的% 模式变成新的可读性更强的 花括号声明{}.用于渲染前的参数引用声明, 花括号里可以用数字代表引用参数的序 ...
- linux 系统性能指标采样脚本
以下脚本写于redmine性能排查时,用于定位系统性能瓶颈的采样,源地址为~/performanceLog/collectLog.sh中,计划放入github的代码片段库中. 注: 如果mysql的地 ...
- SVN的文件夹链接(目录链接,目录映射,svn:externals)
首先大家可以看下SVN的文件夹链接太强大了!(目录链接,目录映射,svn:externals),我就是看了这篇文章才敢大刀阔斧的把项目里的外链修改成正确的链接. 问题: 我们的项目里,服务器脚本工程s ...
- session204 imessageApp sticker part I要点
session204 imessageApp sticker partI 工程文件:https://developer.apple.com/library/prerelease/content/sam ...
- DataInputStream类和RandomAccessFile类的使用方法
// DataInputStream类实现了DataInput接口,要想从文件中读入二进制数据, // 你需要将DataInputStream与某个字节源相结合,例如FileInputStream / ...
- C#排序比较
与C#定义了相等性比较规范一样,C#也定义了排序比较规范,以确定一个对象与另一个对象的先后顺序.排序规范如下 IComparable接口(包括IComparable接口和IComparable< ...
- 读Java 804 - Quick refresher
Upcast永远是成功的,但Downcast不是,记得做instanceof判断 仅抛不同异常,而返回值相同的重载是不可以的 static import只会import静态类 static metho ...
- Spring4 MVC Hibernate4集成 Annotation
Spring4 MVC Hibernate4集成 Annotation 一.本文所用环境 二.工程目录 三.Maven添加依赖 四.新建数据库表 五.配置文件 六.Model层 七.DAO层 八.Se ...
- Windows 8.1 Preview 开发资源汇总
Microsoft Build 2013开发者大会已经结束,从Session安排上看主要以Windows 8.1为主.我相信大家有已经或多或少的体验过Windows 8.1 Preview了,关于操作 ...