hdu5592
来源:互联网 发布:淘宝上好玩的大人玩具 编辑:程序博客网 时间:2024/06/05 00:21
上面的是原题解。我的思路一样,不过使用vector实现的,第一次查找了一遍超时,想了一下原来不用,直接找就行,最后险过,听说线段树特别快。有时间试试
#include <cstdio>#include <string>#include <cstring>#include <fstream>#include <algorithm>#include <cmath>#include <queue>#include <stack>#include <vector>#include <map>#include <set>#include <iomanip>using namespace std;#define maxn 50005#define MOD 1000000007#define mem(a) memset(a , 0 , sizeof(a))#define LL __int64int arr[maxn];int ans [maxn];vector<int>v;int main(){ int t , n; scanf("%d" , &t); while(t--) { v.clear(); scanf("%d" , &n); for(int i = 0 ; i < n ; i ++) { scanf("%d" , &arr[i]); v.push_back(i+1); } int tmp = 0; for(int i = n-1 ; i > 0; i --) { tmp = arr[i] - arr[i-1]; ans[i] = v[i-tmp]; //std::vector<int>::iterator iter=std::find(v.begin(),v.end(),ans[i]); //加了超时 v.erase(v.begin() + i - tmp); //以前是直接<span style="font-family: Arial, Helvetica, sans-serif;">v.erase(iter)</span> } ans[0] = v[0]; for(int i = 0 ; i < n ; i ++) { printf("%d" , ans[i]); if(i != n-1) printf(" "); } printf("\n"); } return 0;}
0 0
- hdu5592
- hdu5592
- HDU5592(线段树)
- hdu5592 线段树
- hdu5592 ZYB's Premutation
- hdu5592-ZYB's Premutation
- HDU5592(线段树+二分)
- HDU5592-ZYB's Premutation
- HDU5592 ZYB's Premutation(树状数组)
- hdu5592&bestcoder Round #65 1003题
- HDU5592 ZYB's Premutation 树状数组应用
- php与json
- java中的String类常量池详解
- linux安装mysql
- 网络编程 同步异步加载 SET POST
- 百度
- hdu5592
- 6大设计原则(五)---迪米特法则
- c库函数
- previous declaration of XXX was here
- webservice并行能力及配置
- #学习笔记#(6)mouseenter-mouseleave显示隐藏内容-jQuery
- Eclipse学习摘记
- 传智播客展望2016年大学毕业生求职现状
- 概要设计和详细设计的区别与联系