【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子列的个数; 然后让你输出 ...
随机推荐
- putty 访问 vmware中ubuntu 方法
putty访问虚拟机 从宿主机中用putty连接虚拟机中的Ubuntu. putty默认使用ssh方式连接,这需要在Ubuntu Server中安装ssh服务.使用命令sudo apt-get ...
- jq 操作table
转载于:http://www.jb51.net/article/34633.htm jquery获取table中的某行全部td的内容方法,需要的朋友可以参考一下 <table>< ...
- MYSQL密码设置
当MYSQL安装成功后,root用户的密码默认是空的,有三种方式可以重新设置root账号的密码 1.用root 进入mysql后 mysql>set password =password('你的 ...
- [WPF]资源字典——程序集之间的资源共享 简单换皮肤
直接上代码,已便已后自己查况阅,新手也可以看! 1.新建一个资料类和一个WPF工程 2.APP.XAML应该资源字典,注意应Source格式,前面一定要有“/” <ResourceDiction ...
- Managing the Lifecycle of a Service
service的生命周期,从它被创建开始,到它被销毁为止,可以有两条不同的路径: A started service 被开启的service通过其他组件调用 startService()被创建. 这种 ...
- 【转】【WPF】资源读取 URI
一开始看到WPF里面经常用如下语句来构造资源文件Uri: Uri uri = new Uri("/AssemblyName;component/image.png"); 我还以为这 ...
- VisualStudio2013+EF6+MySql5.5环境下配置
看院子里对EF框架和MySql的配置文章不少,但是几乎出自一篇文章的转载,而且这篇转载的文章的也比较坑爹,下面我将介绍一下我的配置过程: 第一步:安装mysql-connector-net-6.9.9 ...
- [py]导入模块3种方法
import os <--通过os.system()引用 from os import * <---直接system()引用,不建议使用 from os import argv i ...
- 项目移植将eclipse里面的项目移植到intellij idea里面
怎么关联多个库 . A B C D,A依赖BC,D依赖A,怎么搞? 注意: as和idea里面,project是工作空间的意思,这里面model才是项目. 打开主项目D 打开已经存在的model 导 ...
- [原]iBatis.Net(C#)系列一:简介及运行环境
转载请注明http://www.cnblogs.com/13590/archive/2013/02/27/2934580.html 摘要:介绍iBatis.Net的基本情况和运行原理,运行环境中各参数 ...