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 ...
随机推荐
- Win32 SecuritySetting
http://flylib.com/books/en/2.21.1.207/1/ http://blogs.technet.com/b/heyscriptingguy/archive/2011/11/ ...
- SQL中采用Newtonsoft.Json处理json字符串
原文 SQL中采用Newtonsoft.Json处理json字符串 使用环境: SQL Server2005; VS2010; 关于SQL中部署CLR程序集的方法,网上一搜一大把,需要了解的自行查阅, ...
- android天气查询(二)之网络json数据的获取
前面一篇文章介绍了如何使用ksoap获取天气信息,但是使用的网络资源受到了限制,所以我们这里会采用第二种方法,可以无限制的获取.http://m.weather.com.cn/data/1010101 ...
- Android 关于调用系统内已安装的相机问题
Intent intent=new Intent(MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(intent,1); 调用系统内已安 ...
- [置顶] P2P网贷对推动社会发展的影响
P2P网贷对推动社会发展的影响 1 真正的支持了实体经济,一般借款人就在几万或者50万以下 2 关照小微经济,新型行业.一般小微经济的创新更高,对社会的发展最大化. 3盘活存量 放到银行.保险.国债一 ...
- Scrambled Polygon(凸多边形,斜率)
Scrambled Polygon Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 7805 Accepted: 3712 ...
- powershell 生成随机用户信息
#生成随机用户信息,包括姓名.QQ.邮箱,手机号 $nameArr=@('一','丁','三','专','世','业','丝','中','丰','临','丹','丽','举','乃','义', '乐' ...
- HTTP消息头详解
HTTP是一个属于应用层面的面向对象的协议,由于其便捷.快速的方式.适用于分布式超媒体信息系统.于1990年提出 HTTP 协议主要特点概括如下 1.支持客户/服务器模式. 2.简单快速 请求方法常用 ...
- 在GridView控件里面绑定DropDownList控件
参考链接: http://www.aspsnippets.com/Articles/Populate-DropDownList-with-Selected-Value-in-EditItemTempl ...
- virtual 关键字
virtual 关键字用于修饰方法.属性.索引器或事件声明,并且允许在派生类中重写这些对象.例如,此方法可被任何继承它的类重写. public virtual double Area() { retu ...