【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子列的个数; 然后让你输出 ...
随机推荐
- UESTC 918 WHITE ALBUM --生成树变形
最小生成树变形. 题目已经说得很清楚,要求到达每个房间,只需求一个最小生成树,这时边权和一定是最小的,并且那k个房间一定与所有点都有通路,即一定都可以逃脱. 但是有可能当所有点都有了该去的安全房间以后 ...
- 2014 Super Training #4 G What day is that day? --两种方法
原题: ZOJ 3785 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3785 题意:当天是星期六,问经过1^1+2^2+ ...
- Unity抗锯齿
Unity抗锯齿设置是针对模型,对模型的阴影的锯齿设置无效,不知道我这样的理解是否正确. 遇到的问题 而我是要对灯光照射在模型上产生的阴影进行抗锯齿,暂时还未研究出解决方案,希望知道的朋友告知一声. ...
- 只有 DBA 才能导入由其他 DBA 导出的文件
两句话搞定问题: grant dba to testuser ; 如果还不行,再执行: alter user testuser default role DBA:
- HTML5和css3的总结二
继续接着昨天的整理 [倒影]:用的不是很多 -webkit-box-reflect:below 20px -webkit-linear-gradient(rgba(0,0,0,0,),rgba(0,0 ...
- Contains Duplicate II
Given an array of integers and an integer k, find out whether there there are two distinct indices i ...
- IP+IDC-chinaz抓取
#-*-coding:gbk-*- #code by anyun.org import urllib import re import time def getHtml(url): page = ur ...
- [转]Windows网络编程学习-面向连接的编程方式
直接附上原文链接:windows 网络编程学习-面向连接的编程方式
- How to get date from OAMessageDateFieldBean
OAMessageDateFieldBean dateFromBean = (OAMessageDateFieldBean)webBean.findChildRecursive("pRece ...
- 关于错误提示:此实现不是 Windows 平台 FIPS 验证的加密算法的一部分的解决方案
vs上的一个项目,弄了一个aes加密算法.提示说:调用的目标异常.此实现不是 Windows 平台 FIPS 验证的加密算法的一部分.弄了好久一直不行.解决不了.最后找了半天资料终于解决了.估计下来. ...