解题报告 之 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,以下是我的解题报告索引,每一题几乎都有详细的说明,供各位码农参考.根据我自己做的进度持续更新中...... ...
随机推荐
- vue --- 解读vue的中webpack.base.config.js
const path = require('path') const utils = require('./utils')// 引入utils工具模块,具体查看我的博客关于utils的解释,utils ...
- 74LS153 选择器 【数字电路】
74LS153 我用了八个不同频率的方波信号,用153当作信号选择器,控制环节的开关是4通道的选择器,00 01 10 11分别选择通道 0 1 2 3 以下是八选一的demo
- Android经常使用自己定义控件(二)
经常使用的Android自己定义控件分享 http://www.see-source.com//androidwidget/list.html?type=&p=1
- UDP深入骨髓【转】
从UDP的”连接性”说起–告知你不为人知的UDP 原文地址:http://bbs.utest.qq.com/?p=631 很早就计划写篇关于UDP的文章,尽管UDP协议远没TCP协议那么庞大.复杂,但 ...
- R语言-上海二手房数据分析
案例:通过分析上海的二手房的数据,分析出性价比(地段,价格,未来的升值空间)来判断哪个区位的二手房性价比最高 1.载入包 library(ggplot2) library(Hmisc) library ...
- 7.Maven之(七)pom.xml配置文件详解
转自:https://blog.csdn.net/qq_33363618/article/details/79438044 setting.xml主要用于配置maven的运行环境等一系列通用的属性,是 ...
- eclipse中修改了代码编译后执行不起作用
在网上试了好多方法都没解决 后来,删了eclipse里的服务器,重新创建了一下,重新运行自己的工程发现修改的代码起作用了.
- JS match方法的返回数据的探究
match方法是JS的字符串方法,详细说明可以看MDN的说明. 如果正则表达式匹配成功的话,match方法会返回一个数组,而数组里的数据有两种形式,对应着匹配方式:全局匹配与非全局匹配. 1. 全局匹 ...
- Vue的style与class
1. style 可以通过 :style="{height:`${heightData.main}px`}" 实现样式的动态绑定, style绑定的是一个对象,多个样式时用“,”隔 ...
- HDU 1506 Largest Rectangle in a Histogram(DP)
Largest Rectangle in a Histogram Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...