Codeforces 490B Queue【模拟】
题意还是很好理解的,根据题目给出描述条件然后求出这串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【模拟】的更多相关文章
- codeforces 490B.Queue 解题报告
题目链接:http://codeforces.com/problemset/problem/490/B 题目意思:给出每个人 i 站在他前面的人的编号 ai 和后面的人的编号 bi.注意,排在第一个位 ...
- Codeforces 767B. The Queue 模拟题
B. The Queue time limit per test:1 second memory limit per test:256 megabytes input:standard input o ...
- queue+模拟 Codeforces Round #304 (Div. 2) C. Soldier and Cards
题目传送门 /* 题意:两堆牌,每次拿出上面的牌做比较,大的一方收走两张牌,直到一方没有牌 queue容器:模拟上述过程,当次数达到最大值时判断为-1 */ #include <cstdio&g ...
- Codeforces 389B(十字模拟)
Fox and Cross Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Submi ...
- codeforces D. Queue 找规律+递推
题目链接: http://codeforces.com/problemset/problem/353/D?mobile=true H. Queue time limit per test 1 seco ...
- CodeForces 705C Thor (模拟+STL)
题意:给定三个操作,1,是x应用产生一个通知,2,是把所有x的通知读完,3,是把前x个通知读完,问你每次操作后未读的通知. 析:这个题数据有点大,但可以用STL中的队列和set来模拟这个过程用q来标记 ...
- CodeForces 697B Barnicle 模拟
强行模拟 纪念一下…… #include<stdio.h> #include<iostream> #include<algorithm> #include<m ...
- CodeForces 709B Checkpoints 模拟
题目大意:给出n个点的坐标,和你当前的坐标,求走过n-1个点的最短路程. 题目思路:走过n-1个点,为了使路程更短,那么不走的点只可能第一个点或最后一个点.模拟就行了,比较恶心. #include&l ...
- codeforces 591B Rebranding (模拟)
Rebranding Problem Description The name of one small but proud corporation consists of n lowercase E ...
随机推荐
- Linux 动态库剖析
进程与 API 动态链接的共享库是 GNU/Linux® 的一个重要方面.该种库允许可执行文件在运行时动态访问外部函数,从而(通过在需要时才会引入函数的方式)减少它们对内存的总体占用.本文研究了创建和 ...
- Poj 2371 Questions and answers(排序)
题目链接:http://poj.org/problem?id=2371 思路分析:使用计数排序或其他时间复杂度为O( log N )的排序. 代码如下: #include <iostream&g ...
- weblogic的ejb远程调用
这是一篇对EJB远程调用的简单范例. 1.环境:win7 + weblogic 12c + myeclipse8.5 2.目的:实现在myeclispe中对weblogic中EJ ...
- ASP.NET中IsPostBack的理解
IsPostBack是Page类的一个属性,返回值为一个布尔值. 一般放在Page_Load事件中, 是指是否第一次调用这个页面.当页面是第一次打开时其值为False,若当前页面为一个提交后的页面其值 ...
- CSS3属性值之box-shadow
语法: box-shadow:inset x-offset y-offset blur-radius spread-radius color 也就是: 对象选择器 {box-shadow:投影 ...
- windows版的node.js简单示例
1.下载node.exe放到任意目录,假设E:\nodejs\ 2.在E:\nodejs\下新建helloworld.js,输入以下内容,保存关闭 var http = require('http') ...
- [译]Stairway to Integration Services Level 5 - 增量删除数据
在 dbo.Contact中添加一行记录 Use AdventureWorks go Insert Into dbo.Contact (FirstName, MiddleName, LastName, ...
- java反射机制入门04
需要jxl.jar package com.rainmer.main; import java.io.File; import java.io.IOException; import java.uti ...
- tcpdump使用技巧
tcpdump使用技巧 http://www.veryarm.com/1751.html
- 'nmake' 不是内部或外部命令,VCVARS32.BAT路径问题
'nmake' 不是内部或外部命令,VCVARS32.BAT路径问题 2014-5-24 VC运行不正确基本上都是路径的问题,今天在进行Openssl开发的环境搭建时,需要使用nmake进行源码和库的 ...