【Codeforces Round#279 Div.2】B. Queue
这题看别人的。就是那么诚实。http://www.cnblogs.com/zhyfzy/p/4117481.html
During the lunch break all n Berland State University students lined up in the food court. However, it turned out that the food court, too, has a lunch break and it temporarily stopped working.
Standing in a queue that isn't being served is so boring! So, each of the students wrote down the number of the student ID of the student that stands in line directly in front of him, and the student that stands in line directly behind him.(话说题意理解错是怎么过前三个样例的...) If no one stands before or after a student (that is, he is the first one or the last one), then he writes down number 0 instead (in Berland State University student IDs are numerated from 1).
After that, all the students went about their business. When they returned, they found out that restoring the queue is not such an easy task.
Help the students to restore the state of the queue by the numbers of the student ID's of their neighbors in the queue.
The first line contains integer n (2 ≤ n ≤ 2·105) — the number of students in the queue.
Then n lines follow, i-th line contains the pair of integers ai, bi (0 ≤ ai, bi ≤ 106), where ai is the ID number of a person in front of a student and bi is the ID number of a person behind a student. The lines are given in the arbitrary order. Value 0 is given instead of a neighbor's ID number if the neighbor doesn't exist.
The ID numbers of all students are distinct. It is guaranteed that the records correspond too the queue where all the students stand in some order.
Print a sequence of n integers x1, x2, ..., xn — the sequence of ID numbers of all the students in the order they go in the queue from the first student to the last one.
4
92 31
0 7
31 0
7 141
92 7 31 141
The picture illustrates the queue for the first sample.

附代码(当然也是人家的。0。0)
#include<iostream>
#include<cstdio>
#include<cstdlib>
using namespace std;
const int maxn = ;
int stu[maxn][], l[maxn], r[maxn];
int line[maxn];
int main()
{
//freopen("in.txt", "r", stdin);
int n;
scanf("%d", &n);
for(int i = ; i < n; i++)
{
scanf("%d%d", &l[i], &r[i]);
stu[r[i]][] = l[i];
stu[l[i]][] = r[i];
}
int j, i;
/*找出偶数位的人,并将确定位置的人的值设为-1*/
for(i = stu[][], j = ; i; j+=)
{
line[j] = i;
int tmp = stu[i][];
stu[i][] = -; stu[i][] = -;
i = tmp;
}
/*根据前前位为0找第一个奇数; 开始此处不理解,其实就是在定义的时候已经把第一个奇数的前前位设为0了,而第一个偶数的前前位经上面步骤变为-1,故不会引起冲突*/
for(int k = ; k < n; k++)
{
if(!stu[l[k]][]) {i = l[k]; break;}
}
/*找奇数*/
for(j = ; i; j+=)
{
line[j] = i;
i = stu[i][];
}
for(int l = ; l <= n; l++) {if(l != ) printf(" "); printf("%d", line[l]);}
printf("\n");
return ;
}
难道只能当一题党吗。
【Codeforces Round#279 Div.2】B. Queue的更多相关文章
- 【Codeforces Round #406 (Div. 2)】题解
The Monster 签到题,算一下b+=a和d+=c,然后卡一下次数就可以了. Not Afraid 只要一组出现一对相反数就是安全的. Berzerk 题意:[1,n],两个人轮流走,谁能走到1 ...
- 【Codeforces Round #405 ( Div 2)】题解
Bear and Big Brother 签到题,直接模拟就可以了. Bear and Friendship Condition 满足只能是每个朋友圈中每个人和其他人都是朋友,这样的边数的确定的. 然 ...
- 【Codeforces Round #404 (Div. 2)】题解
A. Anton and Polyhedrons 直接统计+答案就可以了. #include<cstdio> #include<cstring> #include<alg ...
- 【Codeforces Round #518 (Div. 2)】
A:https://www.cnblogs.com/myx12345/p/9847588.html B:https://www.cnblogs.com/myx12345/p/9847590.html ...
- 【Codeforces Round #506 (Div. 3) 】
A:https://www.cnblogs.com/myx12345/p/9844334.html B:https://www.cnblogs.com/myx12345/p/9844368.html ...
- 【Codeforces Round #503 (Div. 2)】
A:https://www.cnblogs.com/myx12345/p/9843198.html B:https://www.cnblogs.com/myx12345/p/9843245.html ...
- 【Codeforces Round #411 (Div. 1)】Codeforces 804C Ice cream coloring (DFS)
传送门 分析 这道题做了好长时间,题意就很难理解. 我们注意到这句话Vertices which have the i-th (1 ≤ i ≤ m) type of ice cream form a ...
- 【Codeforces Round #501 (Div. 3)】
A:https://www.cnblogs.com/myx12345/p/9842904.html B:https://www.cnblogs.com/myx12345/p/9842964.html ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
随机推荐
- error: Setup script exited with error: Unable to find vcvarsall.bat
安装mxnet python版本时遇到“Unable to find vcvarsall.bat”错误搜索一下后查到如下方法: python 3.5.2版本依赖高版本的vs解决办法是安装vs2015的 ...
- Python环境变量设置
在Windows环境下安装了python后,为了方便运行.py文件,可以设置环境变量如下: 环境变量位置 添加值 添加后效果 系统变量中的PATH python.exe所在目录,比如D:\Python ...
- 转载:MATLAB画图常用调整代码
%单y轴 plot(t*1e+,abs(iGG)/max(abs(iGG)),); axis([-,,,]) xlabel('时间/ns'); ylabel('幅度/a.u.'); ,'FontNam ...
- uva 2572 Viva Confetti
思路: 小圆面是由小圆弧围成.那么找出每条小圆弧,如果小圆弧,在小圆弧中点上下左右进行微小位移的所得的点一定在一个小圆面内. 找到最后覆盖这个小点的圆一定是可见的. 圆上的点按照相邻依次排序的关键量为 ...
- 菜鸟学习HTML5+CSS3(一)
主要内容: 1.新的文档类型声明(DTD) 2.新增的HTML5标签 3.删除的HTML标签 4.重新定义的HTML标签 一.新的文档类型声明(DTD) HTML 5的DTD声明为:<!d ...
- leetcode—Palindrome 解题报告
1.题目描述 Given a string s, partition s such that every substring of the partition is a palindrome. Ret ...
- 【转载】grep,egrep,fgrep详解
[转载自]http://blog.csdn.net/homking/article/details/6000711 egrep 等价于 grep -E fgrep 等价于 grep -F grep - ...
- debian 显示器使用自定义分辨率
比如你要使用 1440x900 的自定义分辨率,先利用 cvt 计算一个新的 modeline $ cvt 1440 900 输出为: # 1440x900 59.89 Hz (CVT 1.30MA ...
- HDU 3436--Queue-jumpers (树状数组 or Splay Tree)
树状数组这个真心想了好久,还是没想出来 %%% www.cppblog.com/Yuan/archive/2010/08/18/123871.html 树状数组求前缀和大于等于k的最大值,第一次看到这 ...
- 读取.tmx地图
读取.tmx地图 m_GameMap = CCTMXTiledMap::create("map1.tmx"); this->addChild(m_GameMap,1); 读取 ...