20162017-acmicpc-south-pacific-regional-contest-sppc-16 B.Ballon Warehouse
题意:给你一个无限长且元素均为\(0\)的排列,每次给你一对\((x,y)\),表示在所有\(x\)的后面插入一个元素\(y\),最后给你一个区间\((l,r)\),输出\([l,r-1]\)中的所有元素.
题解:我们用一个vector和pair来存储每次输入的\((x,y)\),显然,在\(x\)后插入的最后一个数一定是\(x\)后的第一个数,所以我们将按顺序插入的pair全部倒置一下,然后从\(0\)开始dfs:
x表示颜色,pos表示位置
我们知道这个排列其实是一个循环节,记\(col\)数组是循环节的元素,\(cnt\)是循环节的长度,长度最多取到\(r\)就行了.
假如\(x\)后面的数的位置大于当前x的位置,那么就不断dfs的去找,用\(col\)来记录.这里最难的就是这个位置的理解,要自己好好推一推!!!.
姑且可以这么认为:pos大的在前面,pos小的在后面,只有v[x].pos>pos才可以dfs下去
最后按循环节来输出即可.
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define me memset
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
using namespace std;
typedef pair<int,int> PII;
typedef pair<long,long> PLL; int n;
int l,r;
int a,b;
int cnt;
int col[N];
vector<PII> v[N]; void dfs(int x,int pos){
if(cnt>=r) return;
col[cnt++]=x;
for(auto w:v[x]){
if(w.se>pos){
printf("%d\n",w.fi);
dfs(w.fi,w.se);
} else return;
}
} int main() {
ios::sync_with_stdio(false);
cin>>n>>l>>r;
for(int i=1;i<=n;++i){
cin>>a>>b;
v[a].pb({b,i});
}
for(int i=0;i<N;++i){
if(!v[i].empty()) reverse(v[i].begin(),v[i].end());
}
dfs(0,0);
for(int i=l;i<r;++i){
printf("%d ",col[i%cnt]);
}
puts(""); return 0;
}
20162017-acmicpc-south-pacific-regional-contest-sppc-16 B.Ballon Warehouse的更多相关文章
- 2016-2017 ACM-ICPC, South Pacific Regional Contest (SPPC 16)
题目链接 Codeforces_Gym_101177 Problem A Anticlockwise Motion 直接模拟即可 #include<iostream> #include ...
- 2016-2017 ACM-ICPC Northeastern European Regional Contest Problem E. Expect to Wait
题目来源:http://codeforces.com/group/aUVPeyEnI2/contest/229509 时间限制:2s 空间限制:512MB 题目大意: 在一个车站中有若干人在队列中等待 ...
- 2016-2017 ACM-ICPC, Egyptian Collegiate Programming Contest (ECPC 16) 题解
题目链接:http://codeforces.com/gym/101147 2017/8/27日训练赛,题目情况9/11,Rank 4/79. A. The game of Osho 题意:定义一个子 ...
- 2016-2017 ACM-ICPC, Asia Tsukuba Regional Contest D Hidden Anagrams
题目链接:http://codeforces.com/gym/101158/attachments /* * @Author: lyucheng * @Date: 2017-10-21 12:20:0 ...
- 2016-2017 ACM-ICPC, Egyptian Collegiate Programming Contest (ECPC 16)
A.The game of Osho(sg函数+二项展开) 题意: 一共有G个子游戏,一个子游戏有Bi, Ni两个数字.两名玩家开始玩游戏,每名玩家从N中减去B的任意幂次的数,直到不能操作判定为输.问 ...
- 2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror) in codeforces(codeforces730)
A.Toda 2 思路:可以有二分来得到最后的数值,然后每次排序去掉最大的两个,或者3个(奇数时). /************************************************ ...
- ACM-ICPC Asia Beijing Regional Contest 2018 Reproduction hihocoder1870~1879
ACM-ICPC Asia Beijing Regional Contest 2018 Reproduction hihocoder1870~1879 A 签到,dfs 或者 floyd 都行. #i ...
- 2017-2018 ACM-ICPC, Asia Daejeon Regional Contest PART(10/12)
$$2017-2018\ ACM-ICPC,\ Asia\ Daejeon\ Regional\ Contest$$ \(A.Broadcast\ Stations\) \(B.Connect3\) ...
- zoj 3659 Conquer a New Region The 2012 ACM-ICPC Asia Changchun Regional Contest
Conquer a New Region Time Limit: 5 Seconds Memory Limit: 32768 KB The wheel of the history roll ...
- 2018 ACM-ICPC Asia Beijing Regional Contest (部分题解)
摘要 本文主要给出了2018 ACM-ICPC Asia Beijing Regional Contest的部分题解,意即熟悉区域赛题型,保持比赛感觉. Jin Yong’s Wukong Ranki ...
随机推荐
- 基于SVM的字母验证码识别
基于SVM的字母验证码识别 摘要 本文研究的问题是包含数字和字母的字符验证码的识别.我们采用的是传统的字符分割识别方法,首先将图像中的字符分割出来,然后再对单字符进行识别.首先通过图像的初步去噪.滤波 ...
- Java基础学习总结笔记
Java基础 Java常用内存区域 栈内存空间:存储引用堆内存空间的地址 堆内存空间:保存每个对象的具体属性内容 全局数据区:保存static类型的属性 全局代码区:保存所有的方法定义 修饰符 权限修 ...
- ptgmk
num >= 1125899906842624 ? "P" \ : num >= 1099511627776 ? "T" \ : num >= ...
- 【Python】PDF转WORD
注意,下文中的PDF文档是纯文字格式,而且非扫描版的PDF文件. 如果是扫描版或者带有图片的.可能转起来会出现排版异常并且图片无法保存到.doc文件中. 正文开始: 需要安装依赖包 pdfminer3 ...
- Ajax函数的封装
Ajax函数的封装 function ajax(options) { // 1 创建Ajax对象 let xhr = new XMLHttpRequest(); // 2 告诉Ajax对象要想哪儿发送 ...
- 1 flume快速入门——十分钟学会flume
flume ## 1.1 Flume定义 Flume是Cloudera提供的一个高可用的,高可靠的,分布式的海量日志采集.聚合和传输的系统.Flume基于流式架构,灵活简单. 大数据框架大致分为3类: ...
- (013)每日SQL学习:日期的各种计算
1.确定两个日期之间的工作日天数 --确定两个日期之间的工作日天数with x0 as (select to_date('2018-01-01','yyyy-mm-dd') as 日期 from du ...
- (转载)微软数据挖掘算法:Microsoft 神经网络分析算法(10)
前言 有段时间没有进行我们的微软数据挖掘算法系列了,最近手头有点忙,鉴于上一篇的神经网络分析算法原理篇后,本篇将是一个实操篇,当然前面我们总结了其它的微软一系列算法,为了方便大家阅读,我特地整理了一篇 ...
- Index-Only Scans and Covering Indexes
小结: 1.覆盖索引 回表 2. All indexes in PostgreSQL are secondary indexes, meaning that each index is stored ...
- Go for Pythonistas Go and the Zen of Python 禅
Go for Pythonistas https://talks.golang.org/2013/go4python.slide#1 Things I don't like about Python ...