【题解】P5462 X龙珠

赛题 #B: P5462 X龙珠 | 满分: 100分

发一个set做法

维护两个set,一个按照顺序排序,一个按照值排序。

每次从大往小取,问题就变成了判断这个最大值后面是否有数,直接查看一下按照顺序排序的该数是否有后继。

编译记得用c++11,请安心食用。

(为了方便理解,按照顺序排序的set写得不够优美)

//@winlere
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<set>
#include<vector> using namespace std; typedef long long ll;
inline int qr(){
register int ret=0,f=0;
register char c=getchar();
while(c<48||c>57)f|=c==45,c=getchar();
while(c>=48&&c<=57) ret=ret*10+c-48,c=getchar();
return f?-ret:ret;
}
typedef pair < int , int > node;
#define x first
#define y second
#define mk make_pair
set < node > s;
set < int ,greater < int > > s1;
int n;
const int maxn=1e5+5;
int arc[maxn];
vector < int > ve;
int main(){
#ifndef ONLINE_JUDGE
freopen("in.in","r",stdin);
//freopen("out.out","w",stdout);
#endif
n=qr();
for(register int t=1,c;t<=n;++t)
s.insert(mk(t,c=qr())),s1.insert(c),arc[c]=t;
for(register int t=1;t<=n>>1;++t){
for(auto it:s1){
auto ti=s.find(mk(arc[it],it));
if(ti!=s.end()&&++ti!=s.end()){
auto t1=*ti--;
auto t2=*ti;
s.erase(t1);
s.erase(t2);
ve.push_back(t2.second);
ve.push_back(t1.second);
s1.erase(t1.second);
s1.erase(t2.second);
break; }
}
}
int cnt=0;
for(auto t:ve) printf("%d%c",t,++cnt==n?'\n':' ');
return 0;
}

【题解】P5462 X龙珠的更多相关文章

  1. 【题解】X龙珠

    明天好像要考链表今晚笔者来了解下. 题目链接 解: 对于这道题,由于前面要与后面重新连起来,于是我们考虑链表. 我们先正常用链表维护关系.然后,我们从大到小枚举. 对于这个数,如果它后面有数(因为是一 ...

  2. Cube Stacking(并差集深度+结点个数)

    Cube Stacking Time Limit: 2000MS   Memory Limit: 30000K Total Submissions: 21567   Accepted: 7554 Ca ...

  3. [题解][洛谷]_U75702/P5462_X龙珠_论何为字典序

    赛时嫌麻烦,没写 赛后自闭了,写了一下午 题目描述 “X龙珠”是一款益智小游戏.游戏中有 n(2|n)n(2∣n) 个编号互不相同龙珠按照给定的顺序排成一个队列,每个龙珠上面都有一个编号.每次操作时, ...

  4. 2016 华南师大ACM校赛 SCNUCPC 非官方题解

    我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...

  5. noip2016十连测题解

    以下代码为了阅读方便,省去以下头文件: #include <iostream> #include <stdio.h> #include <math.h> #incl ...

  6. BZOJ-2561-最小生成树 题解(最小割)

    2561: 最小生成树(题解) Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1628  Solved: 786 传送门:http://www.lyd ...

  7. Codeforces Round #353 (Div. 2) ABCDE 题解 python

    Problems     # Name     A Infinite Sequence standard input/output 1 s, 256 MB    x3509 B Restoring P ...

  8. 哈尔滨理工大学ACM全国邀请赛(网络同步赛)题解

    题目链接 提交连接:http://acm-software.hrbust.edu.cn/problemset.php?page=5 1470-1482 只做出来四道比较水的题目,还需要加强中等题的训练 ...

  9. 2016ACM青岛区域赛题解

    A.Relic Discovery_hdu5982 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Jav ...

随机推荐

  1. @loj - 2250@ 「ZJOI2017」仙人掌

    目录 @题目描述@ @solution@ @accepted code@ @details@ @题目描述@ 如果一个无自环无重边无向连通图的任意一条边最多属于一个简单环,我们就称之为仙人掌.所谓简单环 ...

  2. Pytorch使用tensorboardX可视化。超详细!!!

    tensorboard --logdir runs 改为 tensorboard --logdir=D:\model\tensorboard\runs 重点 在网上看了很多方法后发现将原本链接中的计算 ...

  3. pytorch nn.Embedding

    pytorch nn.Embeddingclass torch.nn.Embedding(num_embeddings, embedding_dim, padding_idx=None, max_no ...

  4. Vue6——v-model实现数据双向绑定

    博客地址 :https://www.cnblogs.com/sandraryan/ v-model 用于input标签,用于实现双向绑定,及时把数据的变化渲染在页面 双向绑定及原理 举个双向绑定的简单 ...

  5. 学习CSS预处理器Less

    1.Sass与Less的区别:Sass与Less的区别 2.Less的使用:Less的使用 3.Less的相关网址:Less.js.Less中文网 Less的HSL函数-lighten():HSL函数 ...

  6. 2018-8-10-win10-uwp-读取保存WriteableBitmap-、BitmapImage

    title author date CreateTime categories win10 uwp 读取保存WriteableBitmap .BitmapImage lindexi 2018-08-1 ...

  7. C# 16 进制字符串转 int

    最近在写硬件,发现有一些测试是做 16 进制的字符串,需要把他转换为整形才可以处理. 本文告诉大家如何从 16 进制转整形 如果输入的是 0xaa 这时转换 int 不能使用 Parse 不然会出现异 ...

  8. Vue 列表动画实现

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  9. 【js】 vue 2.5.1 源码学习(十二)模板编译

    大体思路(十) 本节内容: 1. baseoptions 参数分析 2. options 参数分析 3. parse 编译器 4. parseHTNL 函数解析 // parse 解析 parser- ...

  10. UVa 12325 - Zombie's Treasure Chest-[分类枚举]

    12325 Zombie’s Treasure Chest Some brave warriors come to a lost village. They are very lucky and fi ...