题意还是很好理解的,根据题目给出描述条件然后求出这串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. java 读文件 解析

    [Java]读取文件方法大全   1.按字节读取文件内容2.按字符读取文件内容3.按行读取文件内容 4.随机读取文件内容 public class ReadFromFile {     /**     ...

  2. [LeetCode]题解(python):070-Climbing Stairs

    题目来源: https://leetcode.com/problems/climbing-stairs/ 题意分析: 爬楼梯,一次可以爬一步或者两步.如果要爬n层,问一共有多少种爬法.比如说,如果是3 ...

  3. 两种解决Qt5显示中文乱码的方法(使用QStringLiteral和#pragma execution_character_set("utf-8")两种方法)

    升级到Qt5.X之后,原先解决的Qt显示中文乱码的方法突然不适用了,找了很多方式来解决这个问题第一种:在公司代码里看到的方法,先将对应的cpp文件用windows自带的记事本打开,另存为UTF-8格式 ...

  4. 用git上传项目到github

    1 git  clone  github仓库地址 2 git add . 3 git  commit -m "changes log" 4 git remote add origi ...

  5. JS于,子类调用父类的函数

    概要 JS虽然没有直接有面向对象的特性,但还是能prototype为了模拟面向对象的特性,如继承和多态.而大多数面向对象的语言(例如C++.Java等一下)相比,JS为了实现面向对象还是有点繁琐,抽象 ...

  6. c基础总结

    机器大小端判断: #include <stdio.h> typedef union{ char x; int i; }un; int main() { un tt; tt.i = ; ) ...

  7. 2.4.5 用NPOI操作EXCEL--插入图片

    我们知道,在Excel中是可以插入图片的.操作菜单是“插入->图片”,然后选择要插入图片,可以很容易地在Excel插入图片.同样,在NPOI中,利用代码也可以实现同样的效果.在NPOI中插入图片 ...

  8. 总结一下ASP.NET MVC 网站的部署问题

    总结一下ASP.NET MVC 网站的部署问题 近日,准备把MVC建了一个新的测试站点部署到IIS上面,结果没想到出现了一系列的问题和错误,准备记录一下. 第一个问题,就是如何将MVC的站点部署到II ...

  9. UML初了解

    最近项目中有看UML图,很是模糊一些东西,今天查资料,发现这篇博文很好,转载了,也解了不少疑惑. 原文:http://www.uml.org.cn/oobject/201008311.asp 在绘画U ...

  10. Oracle存储包存储及案例

    Package左侧文件: create or replace package S02_ZFRZPT_YS_MID is procedure start_cal(strgranularity in va ...