【CodeForces 504A】Misha and Forest
题意
有n个点,代号分别为0到n-1,然后第i个点有di个相连点,与i 相连的点的XOR sum 为si,求所有的边。
分析
知识:a^b^a=b,a^b^b=a.
把相连点为1的i存进队列,i的唯一相连点就是S。
然后得到一条边i到s,对i的相连点S,d--,s^=i,就相当于去掉i这个点。
然后再判断S的相连点d是不是1,是1则进入队列。
直到队列为空。
代码
#include<cstdio>
#include<algorithm>
#include<queue>
#define N 100005 using namespace std; int n,b;
int ex[N],ey[N],d[N],s[N]; queue<int> q; int main()
{
scanf("%d",&n);
for(int i=; i<n; i++)
{
scanf("%d%d",&d[i],&s[i]);
if(d[i]==)q.push(i);
} while(!q.empty())
{
int i=q.front();
q.pop();
if(d[i]==)
{
ex[b]=i;
ey[b]=s[i];
b++; s[s[i]]^=i;
d[s[i]]--;
if(d[s[i]]==) q.push(s[i]);
}
} printf("%d\n",b);
for(int i=; i<b; i++)
printf("%d %d\n",ex[i],ey[i]);
return ;
}
【CodeForces 504A】Misha and Forest的更多相关文章
- 【Codeforces 501C】Misha and Forest
[链接] 我是链接,点我呀:) [题意] 给你一棵树 但是每个节点只告诉你出度个数 以及所有和它相连的点的异或和. 让你还原这棵树 [题解] 叶子节点的话,他所有节点的异或和就是它那唯一的一个爸爸 因 ...
- 【codeforces 755C】PolandBall and Forest
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【codeforces 501D】Misha and Permutations Summation
[题目链接]:http://codeforces.com/problemset/problem/501/D [题意] 给你两个排列; 求出它们的字典序num1和num2; 然后让你求出第(num1+n ...
- 【CodeForces - 501B 】Misha and Changing Handles(map)
Misha and Changing Handles CodeForces原题是英文,这里就直接上中文好了,翻译不是太给力,但是不影响做题 ^▽^ Description 神秘的三角洲里还有一个传说 ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【25.64%】【codeforces 570E】Pig and Palindromes
time limit per test4 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
- 【codeforces 709D】Recover the String
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
随机推荐
- HDU 4568 Hunter 最短路+状压DP
题意:给一个n*m的格子,格子中有一些数,如果是正整数则为到此格子的花费,如果为-1表示此格子不可到,现在给k个宝藏的地点(k<=13),求一个人从边界外一点进入整个棋盘,然后拿走所有能拿走的宝 ...
- java 19 -15 File类批量更改文件名的方法
/* 需求: * 把H:\三国演义下面的视频名称修改为 00?_介绍.avi 思路: A:封装目录 B:获取该目录下所有的文件的File数组 C:遍历该File数组,得到每一个File对象 D:拼接一 ...
- 异常:NSException和NSAssert的简单使用
//断言 - (void)NSAssert_Test:(NSString *)string{ NSAssert(string == nil, @"string == kong or nil& ...
- 层叠上下文(The stacking context)
MDNThe stacking context 层叠上下文是HTML元素的三维概念,这些HTML元素在一条假想的相对于面向(电脑屏幕的)视窗或者网页的用户的z轴上延伸,HTML元素依据其自身属性按照优 ...
- Rdlc报表出现空白页解决方法(转)
在使用RDLC报表时,碰到这种情况:当只有一页数据时,报表确显示两页,第二页除了报表头之外数据为空.然后,当有多页数据时,最后一页为空. 这个问题很奇怪,网上有很多解决方案,以下的方法可以解决此问题. ...
- LUA GC 简单测试
function table.count(t) if type(t) ~= "table" then assert(false) return end for k, _ in pa ...
- VS2010报错无法编译:LINK : fatal error LNK1123: failure during conversion to COFF: file invalid
win7 64位 专业版 + vs2010 从vc6.0下转过来的一个项目,突然遇到这个问题. 解决方案: 用C:\Windows\winsxs\x86_netfx-cvtres_for_vc_and ...
- [CareerCup] 12.2 Find the Reason of Crash 找到程序崩溃的原因
12.2 You are given the source to an application which crashes when it is run. After running it ten t ...
- LeetCode:Unique Paths I II
Unique Paths A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagra ...
- 利用javascript和WebGL绘制地球 【翻译】
利用javascript和WebGL绘制地球 [翻译] 原翻译:利用javascript和WebGL绘制地球 [翻译] 在我们所有已知的HTML5API中,WebGL可能是最有意思的一个,利用这个AP ...