【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 ...
随机推荐
- MSP430主系统时钟以及430的低功耗设置
如何将系统时钟设置到外部高频晶体振荡器,430的MCLK默认的是DCO的,如何安全的从DCO切换到外部晶体振荡器,这是一个很重要的步骤,因为经过此步骤,可以极大地提高430的处理能力,DCO在内部,可 ...
- (二)GameMaker:Studio ——使用等高图生成3D地形
上一篇,我们讲解了GM中导入模型的方法,这节我们来讲地形. 源文件地址:http://pan.baidu.com/share/link?shareid=685772423&uk=2466343 ...
- 你知道C/S和B/S两种架构有什么区别吗?
C/S和B/S,是再普通不过的两种软件架构方式,都可以进行同样的业务处理,甚至也可以用相同的方式实现共同的逻辑.既然如此,为何还要区分彼此呢?那我们就来看看二者的区别和联系. 一.C/S 架构 ...
- 【转载】chmod u+s
转自:http://blog.chinaunix.net/uid-26642180-id-3378119.html Set uid, gid,sticky bit的三个权限的详细说明 一个文件都有一个 ...
- HDU-4612 Warm up 边双连通分量+缩点+最长链
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4612 简单图论题,先求图的边双连通分量,注意,此题有重边(admin还逗比的说没有重边),在用targ ...
- Umbraco Forms 使Rendering Forms scripts 在不同的template中
具体请参考 https://our.umbraco.org/documentation/products/umbracoforms/developer/Rendering-Scripts/ 转载 ht ...
- Altium Designer生成网表 导出网表【worldsing笔记】
Design -> Netlist for project -> Protel
- ST-Link 驱动安装
电脑中可以预先安装一个ST Visual Programmer 这个直接带STLink驱动或是安装一个STM32 ST-Link Uitilty 然后选择自安安装 点出下一步 在弹出的对话框选择“仍然 ...
- SQL提高查询效益之in、not in、between、like等条件讲述
在使用SQL语句查询数据库记录时,如果要查询相同的内容,有着不同的多种方法. 仍然,尽管使用多种方法可以得到相同的结果,但是,如果您使用不同的方法,在执行效益上是截然不同的.因此,我们得仔细考虑,如果 ...
- HTTP笔记:URI与URL
URI与URL 简单理解是这样的:理解URI和URL的区别,我们引入URN这个概念.URI = Universal Resource Identifier 统一资源标志符URL = Universal ...