解题报告 之 HDU5305 Friends
解题报告 之 HDU5305 Friends
Description
peopleand
pairsof friends. For every pair of friends, they can choose to become online friends (communicating using online applications) or offline friends (mostly using face-to-face communication). However, everyone in these
rev=2.4-beta-2" alt="" style=""> people
wants to have the same number of online and offline friends (i.e. If one person has
onine
friends, he or she must have
offline
friends too, but different people can have different number of online or offline friends). Please determine how many ways there are to satisfy their requirements.
Input



rev=2.4-beta-2" alt="" style="">



,
indicating the number of testcases.
For each testcase, the first line contains two integers
rev=2.4-beta-2" alt="" style="">
rev=2.4-beta-2" alt="" style="">
rev=2.4-beta-2" alt="" style="">
rev=2.4-beta-2" alt="" style="">


and 

rev=2.4-beta-2" alt="" style="">
rev=2.4-beta-2" alt="" style="">

rev=2.4-beta-2" alt="" style="">

rev=2.4-beta-2" alt="" style="">



,
indicating the number of people and the number of pairs of friends, respectively. Each of the next
lines
contains two numbers
and
rev=2.4-beta-2" alt="" style="">,
which mean
and
are
friends. It is guaranteed that 
rev=2.4-beta-2" alt="" style="">
rev=2.4-beta-2" alt="" style=""> and
every friend relationship will appear at most once.
Output
Sample Input
2
3 3
1 2
2 3
3 1
4 4
1 2
2 3
3 4
4 1
Sample Output
0
2
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring> using namespace std;
typedef long long ll; int de[10];
int in[100], out[100];
int on[10], off[10];
int ans, m, n; void dfs( int u )
{
if(u == m + 1)
{
for(int i = 1; i <= n; i++)
{
if(on[i] != off[i]) return;
}
ans++;
return;
} if(on[in[u]] < de[in[u]] / 2 && on[out[u]] < de[out[u]]/2)
{
on[in[u]]++; on[out[u]]++;
dfs( u + 1 );
on[in[u]]--; on[out[u]]--;
} if(off[in[u]] < de[in[u]] / 2 && off[out[u]] < de[out[u]]/2)
{
off[in[u]]++; off[out[u]]++;
dfs( u + 1 );
off[in[u]]--; off[out[u]]--;
}
} int main()
{
int kase; scanf( "%d", &kase );
while(kase--)
{
memset( de, 0, sizeof de );
memset( on, 0, sizeof on );
memset( off, 0, sizeof off );
ans = 0; scanf( "%d%d", &n, &m );
for(int i = 1; i <= m; i++)
{
scanf( "%d%d", &in[i], &out[i] );
de[in[i]]++; de[out[i]]++;
} int flag = true;
for(int i = 1; i <= n; i++)
{
if(de[i] % 2 == 1)
{
printf( "0\n" );
flag = false;
break;
}
} if(!flag) continue; dfs( 1 );
printf( "%d\n", ans );
}
return 0;
}
解题报告 之 HDU5305 Friends的更多相关文章
- CH Round #56 - 国庆节欢乐赛解题报告
最近CH上的比赛很多,在此会全部写出解题报告,与大家交流一下解题方法与技巧. T1 魔幻森林 描述 Cortana来到了一片魔幻森林,这片森林可以被视作一个N*M的矩阵,矩阵中的每个位置上都长着一棵树 ...
- 二模13day1解题报告
二模13day1解题报告 T1.发射站(station) N个发射站,每个发射站有高度hi,发射信号强度vi,每个发射站的信号只会被左和右第一个比他高的收到.现在求收到信号最强的发射站. 我用了时间复 ...
- BZOJ 1051 最受欢迎的牛 解题报告
题目直接摆在这里! 1051: [HAOI2006]受欢迎的牛 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 4438 Solved: 2353[S ...
- 习题:codevs 2822 爱在心中 解题报告
这次的解题报告是有关tarjan算法的一道思维量比较大的题目(真的是原创文章,希望管理员不要再把文章移出首页). 这道题蒟蒻以前做过,但是今天由于要复习tarjan算法,于是就看到codevs分类强联 ...
- 习题:codevs 1035 火车停留解题报告
本蒟蒻又来写解题报告了.这次的题目是codevs 1035 火车停留. 题目大意就是给m个火车的到达时间.停留时间和车载货物的价值,车站有n个车道,而火车停留一次车站就会从车载货物价值中获得1%的利润 ...
- 习题: codevs 2492 上帝造题的七分钟2 解题报告
这道题是受到大犇MagHSK的启发我才得以想出来的,蒟蒻觉得自己的代码跟MagHSK大犇的代码完全比不上,所以这里蒟蒻就套用了MagHSK大犇的代码(大家可以关注下我的博客,友情链接就是大犇MagHS ...
- 习题:codevs 1519 过路费 解题报告
今天拿了这道题目练练手,感觉自己代码能力又增强了不少: 我的思路跟别人可能不一样. 首先我们很容易就能看出,我们需要的边就是最小生成树算法kruskal算法求出来的边,其余的边都可以删掉,于是就有了这 ...
- NOIP2016提高组解题报告
NOIP2016提高组解题报告 更正:NOIP day1 T2天天爱跑步 解题思路见代码. NOIP2016代码整合
- LeetCode 解题报告索引
最近在准备找工作的算法题,刷刷LeetCode,以下是我的解题报告索引,每一题几乎都有详细的说明,供各位码农参考.根据我自己做的进度持续更新中...... ...
随机推荐
- uva 11248 最小割
Dinic 1 #include<iostream> #include<string> #include<algorithm> #include<cstdli ...
- linux环境下禅道搭建
1.下载禅道安装包,根据操作系统的版本: 2.上传包到linux的opt目录中: 3.解压包: cd /opt tar xzvf 禅道包名称,如:tar xzvf ZenTaoPMS.8.1.3.zb ...
- Codefroces B. New Skateboard
B. New Skateboard time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- Spring AOP那些学术概念—通知、增强处理连接点(JoinPoint)切面(Aspect)(转)
1.我所知道的AOP 初看起来,上来就是一大堆的术语,而且还有个拉风的名字,面向切面编程,都说是OOP的一种有益补充等等.一下让你不知所措,心想着:管不得很多人都和我说AOP多难多难.当我看进去以后, ...
- AES与RAS结合加解密方案
import java.io.IOException; import java.security.InvalidKeyException; import java.security.KeyFactor ...
- Java7与G1
Lucene 4.8開始不支持java6了,所以在下次版本号升级之前我们要先升级至java7. 我使用1/3的全量索引(7.3G).进行測试,20并发,40万请求: sun jdk 1.6.0_26 ...
- php excel文件导出之phpExcel扩展库
php Excel 文件导出 phpExcel 官网 http://phpexcel.codeplex.com/ /** * 导出特定文件 * 依据详细情况而定 */ public function ...
- thinkphp缓存使用
thinkphp缓存使用 一.总结 1.这里的缓存不是指的缓存的页面,而是cache,如果你缓存了一个数组,那么你就可以取出这个数组里面的数据进行使用,用法性质和cookie和session有点像 2 ...
- Objective-C基础笔记(9)Foundation常用类NSArray
NSArray用来存储对象的有序列表,它是不可变的 NSArray不能存储C语言中的基本数据类型,如int.float.enum.struct,也不能存储nil,nil代表数组元素的结束 // // ...
- golang 写文件
package main import ( "bufio" "fmt" "io" "os" ) func main() ...