题意还是很好理解的,根据题目给出描述条件然后求出这串QUEUE

我的做法就是用两个数组 before[] 和 after[] 表示 ai 前面的前面的人的学号 和 ai 后面的后面的人的学号

ex[] 表示 ai 这个人在输入的时候出现的次数,这个数组用于当人数为奇数的时候,寻找第1个人学号,只要遍历一遍1 - 10^6即可

具体还是看代码吧 QAQ ,感觉代码还是比较好理解的。

【这道题目 RE 起码5次,真正原因是数组没有开到位 = = ,也真是觉得自己最近没有写代码了好弱..........

 //#pragma comment(linker, "/STACK:16777216") //for c++ Compiler
#include <stdio.h>
#include <iostream>
#include <cstring>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#define ll long long
#define Max(a,b) (((a) > (b)) ? (a) : (b))
#define Min(a,b) (((a) < (b)) ? (a) : (b))
#define Abs(x) (((x) > 0) ? (x) : (-(x))) using namespace std; const int INF = 0x3f3f3f3f;
int a[], ex[];
int before[], after[]; int main(){
int i, j ,k, t, n, m;
int uu, vv, cur, pos;
while(EOF != scanf("%d",&n)){
memset(ex, , sizeof(ex));
memset(before, -, sizeof(before));
memset(after, -, sizeof(after));
for(i = ; i <= n; ++i){
scanf("%d%d",&uu,&vv);
after[uu] = vv;
before[vv] = uu;
if(uu == ){
a[] = vv;
} else if(vv == ){
a[n - ] = uu;
} else{
++ex[uu];
++ex[vv];
}
}
if(n % == ){
cur = a[];
pos = ;
while(pos != n){
pos += ;
cur = a[pos] = after[cur];
}
cur = a[n - ];
pos = n - ;
while(pos != ){
pos -= ;
cur = a[pos] = before[cur];
}
} else{
cur = a[];
pos = ;
while(pos != n - ){
pos += ;
cur = a[pos] = after[cur];
}
for(i = ; i <= ; ++i){ //2 nums
if(ex[i] == && before[i] == -){
break;
}
}
a[] = i;
cur = a[];
pos = ;
while(pos != n){
pos += ;
cur = a[pos] = after[cur];
}
} for(i = ; i <= n; ++i){
printf("%d ",a[i]);
}
printf("\n");
}
return ;
}
/*
8
3 0
5 4
1 5
0 7
11 9
9 6
6 3
7 1
5
3 0
5 3
0 5
6 4
4 2
*/

Codeforces 490B Queue【模拟】的更多相关文章

  1. codeforces 490B.Queue 解题报告

    题目链接:http://codeforces.com/problemset/problem/490/B 题目意思:给出每个人 i 站在他前面的人的编号 ai 和后面的人的编号 bi.注意,排在第一个位 ...

  2. Codeforces 767B. The Queue 模拟题

    B. The Queue time limit per test:1 second memory limit per test:256 megabytes input:standard input o ...

  3. queue+模拟 Codeforces Round #304 (Div. 2) C. Soldier and Cards

    题目传送门 /* 题意:两堆牌,每次拿出上面的牌做比较,大的一方收走两张牌,直到一方没有牌 queue容器:模拟上述过程,当次数达到最大值时判断为-1 */ #include <cstdio&g ...

  4. Codeforces 389B(十字模拟)

    Fox and Cross Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submi ...

  5. codeforces D. Queue 找规律+递推

    题目链接: http://codeforces.com/problemset/problem/353/D?mobile=true H. Queue time limit per test 1 seco ...

  6. CodeForces 705C Thor (模拟+STL)

    题意:给定三个操作,1,是x应用产生一个通知,2,是把所有x的通知读完,3,是把前x个通知读完,问你每次操作后未读的通知. 析:这个题数据有点大,但可以用STL中的队列和set来模拟这个过程用q来标记 ...

  7. CodeForces 697B Barnicle 模拟

    强行模拟 纪念一下…… #include<stdio.h> #include<iostream> #include<algorithm> #include<m ...

  8. CodeForces 709B Checkpoints 模拟

    题目大意:给出n个点的坐标,和你当前的坐标,求走过n-1个点的最短路程. 题目思路:走过n-1个点,为了使路程更短,那么不走的点只可能第一个点或最后一个点.模拟就行了,比较恶心. #include&l ...

  9. codeforces 591B Rebranding (模拟)

    Rebranding Problem Description The name of one small but proud corporation consists of n lowercase E ...

随机推荐

  1. IOS 表视图(UITableVIew)的使用方法(5)表视图的编辑功能(删除)

    默认的,如果表视图支持编辑,那用户可以通过两种方式来删除某些行,其一为单击左侧的红色按钮后行右侧显示“Delete”按钮,其二为在单元行上的手指向左滑动,“Delete”按钮也会出现供用户单击.无论哪 ...

  2. 27_Blog Reader

    这个App是用来读取 Official Google Blog 的内容,然后显示出来. 用了新建工程时用了 Master-Detail Application 这个模板.用了Core Data用来存储 ...

  3. Mac OS X Mavericks or Yosemite 安装Nginx、PHP、Mysql、phpMyAdmin

    翻译:http://blog.frd.mn/install-nginx-php-fpm-mysql-and-phpmyadmin-on-os-x-mavericks-using-homebrew/ 最 ...

  4. 宣布正式发布 Windows Azure 多重身份验证

    身份和访问管理是安全之锚,是企业 IT 部门的首要任务.它是随时随地向员工.合作伙伴和客户提供访问的关键所在.今天,我们非常高兴地宣布正式发布 Windows Azure 多重身份验证,从而为 IT ...

  5. JAVA GUI学习 - JFileChooser文件选择器组件学习:未包括JFileChooser系统类学习

    public class JFileChooserKnow { /** * @param args */ public static void main(String[] args) { // TOD ...

  6. hdoj 3065 病毒侵袭持续中(AC自动机)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3065 思路分析:问题需要模式匹配多个模式串,需要注意的是模式串会包含和重叠,需要对AC自动机的匹配过 ...

  7. JS实现日历控件选择后自动填充

    最近在做人事档案的项目,在做项目的初期对B/S这块不是很熟悉,感觉信心不是很强,随着和师哥同组人员的交流后发现,调试程序越来越好了,现在信心是倍增,只要自己自己踏实的去研究.理解代码慢慢的效果就出来了 ...

  8. android api 中文 (75)—— AdapterView.OnItemClickListener

    前言 本章内容是android.widget.AdapterView.OnItemClickListener,版本为Android 2.3 r1,翻译来自"麦子",欢迎大家与他交流 ...

  9. js如何判断一个对象是不是Array?(转载)

    js如何判断一个对象是不是Array? 在开发中,我们经常需要判断某个对象是否为数组类型,在Js中检测对象类型的常见方法都有哪些呢? typeof 操作符 对于Function, String, Nu ...

  10. [译]SSRS 报表版本控制

    问题 如今商务智能应用广泛,对我们的商业愈加重要. 对新报表和的各种需求不断攀升. 自 SQL Server 2008 R2的 Reporting Services (SSRS) 开始,微软视图为减轻 ...