HDU3118-利用二进制状态和二分图的性质(好题)
来源:互联网 发布:公司礼品 知乎 编辑:程序博客网 时间:2024/05/29 18:36
Arbiter
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 1242 Accepted Submission(s): 609
Problem Description
Arbiter is a kind of starship in the StarCraft science-fiction series. The Arbiter-class starship is a Protoss warship specializing in providing psychic support. Arbiters were crewed exclusively by Judicators; unlike other warships that were manned predominantly by Templar. The Judicator used the Arbiter as a base to provide support using space-time manipulation.
Arbiters could weaken space-time, tearing rifts in the fabric of space-time, creating a vortex linking another location to the Arbiter’s location. This could be used to move personnel over long distances between stars.
In the meantime of widely used Arbiter to transfer, KMXS, the captain of one Arbiter, was warning that some person had got a serious mental disorder after the trip on his Arbiter. By using mice as model animals, he found the sake, it’s because of chirality!
Every person has chirality, either left-handed or right-handed. Actually all the persons must live with the food which has the same chirality. When one person took Arbiter from one star to another one, his chirality will be changed (from left-handed to right-handed or from right-handed to left-handed). If a person took a long trip and finally got back to his own star, however, his chirality might be changed to the opposite state other than his original, which would cause fatal mental disorder, or even death.
KMXS has the channels map among the starts and he need to prohibit minimum number of channels from traveling so that wherever a person starts his traveling from when he gets his original star he’ll be safe. KMXS turns to your help.
Arbiters could weaken space-time, tearing rifts in the fabric of space-time, creating a vortex linking another location to the Arbiter’s location. This could be used to move personnel over long distances between stars.
In the meantime of widely used Arbiter to transfer, KMXS, the captain of one Arbiter, was warning that some person had got a serious mental disorder after the trip on his Arbiter. By using mice as model animals, he found the sake, it’s because of chirality!
Every person has chirality, either left-handed or right-handed. Actually all the persons must live with the food which has the same chirality. When one person took Arbiter from one star to another one, his chirality will be changed (from left-handed to right-handed or from right-handed to left-handed). If a person took a long trip and finally got back to his own star, however, his chirality might be changed to the opposite state other than his original, which would cause fatal mental disorder, or even death.
KMXS has the channels map among the starts and he need to prohibit minimum number of channels from traveling so that wherever a person starts his traveling from when he gets his original star he’ll be safe. KMXS turns to your help.
Input
The first line of input consists of an integer T, indicating the number of test cases.
The first line of each case consists of two integers N and M, indicating the number of stars and the number of channels. Each of the next M lines indicates one channel (u, v) which means there is a bidirectional channel between star u and star v (u is not equal to v).
The first line of each case consists of two integers N and M, indicating the number of stars and the number of channels. Each of the next M lines indicates one channel (u, v) which means there is a bidirectional channel between star u and star v (u is not equal to v).
Output
Output one integer on a single line for each case, indicating the minimum number of channels KMXS must prohibit to avoid mental disorder.
Constraints
0 < T <= 10
0 <= N <= 15 0 <= M <= 300
0 <= u, v < N and there may be more than one channel between two stars.
Constraints
0 < T <= 10
0 <= N <= 15 0 <= M <= 300
0 <= u, v < N and there may be more than one channel between two stars.
Sample Input
13 30 11 22 0
Sample Output
1
Source
2009 Asia Wuhan Regional Contest Online
题目大意:
给你一张有向图,问你最少删除的边数使得图中没有奇数环,即环的点数为奇数(1除外)
题目思路:
首先我们看看二分图的定义:无向图G=<V,E>为二分图的充要条件是G的所有回路的长度均为偶数。
所以我们可以利用二分图的性质来做这题,首先我们可以利用二进制的来枚举他的所有二分图的组合,二进制中1和0分别属于不同的集合,然后我们在枚举同一集合当中的点是否存在边,如果存在边就删掉该边,然后在记录删除的次数,最后取个最小值就是我们要求的答案
AC代码:
#include<cstring>#include<cstdio>#define min(x,y) (x<y?x:y)int mp[20][20];int n,m;int sove(int k){ int num=0; for(int i=0;i<n;i++){ for(int j=i+1;j<n;j++){ if((1&(k>>i))==(1&(k>>j))&&mp[i][j])num+=mp[i][j]; //枚举所有同一集合的点的组合看是否有边 } } return num;}int main(){ int t;scanf("%d",&t); while(t--){ memset(mp,0,sizeof(mp)); scanf("%d%d",&n,&m); while(m--){ int u,v;scanf("%d%d",&u,&v); mp[u][v]++,mp[v][u]++; //记录边出现的次数 } int ans = 1e8; for(int i=1;i<(1<<n);i++){ //枚举所有状态 ans=min(ans,sove(i)); //取所有状态的最小值 } if(ans==1e8)ans=0; printf("%d\n",ans); } return 0;}
0 0
- HDU3118-利用二进制状态和二分图的性质(好题)
- hdu3118二分图性质的应用
- hdu3118(二分图位判断)
- 二分图的性质
- 二分图的性质
- HDU3118Arbiter (二分图的本质(好题)+二进制枚举)
- 二分图的一些性质
- hdu 3118 Arbiter 二分图的性质
- HDU3478 【判奇环/二分图的性质】
- 二分图性质
- 二分图一些性质
- 二分图有关性质
- 二分图一些性质
- 二分图性质
- 二分图性质
- 二分图相关性质
- 二分图性质
- 二分图性质总结
- HTTP请求方法对照表
- 前端性能优化——个人搜集总结
- 2016年个人书单
- Java开发者常犯的10个错误
- DxO OpticsPro 11.4.0.11979 Windows 简体中文 汉化版 送4部教程
- HDU3118-利用二进制状态和二分图的性质(好题)
- 选择排序 , 插入排序 , 冒泡排序
- MVC 后台代码 获取分布页内容 html 内容
- Unity预计算全局光照的学习(速度优化,LightProbe,LPPV)
- oracle一步一步学习(二)
- 形式名词 :つもり
- 当ScrowView嵌套listView加载完数据后列表自动滚动到最顶端的问题
- 8月4号--完善
- 【数论】计算组合数