Arbiter

Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)

Total Submission(s): 773 Accepted Submission(s): 401

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.
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).
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.
Sample Input
1
3 3
0 1
1 2
2 0
Sample Output
1
题意:一个人从通道一个星球到还有一个星球他的左手变右手,右手变左手。假设存在回到原来的星球他的左右手不是原来的状态的话。这是致命的,为了使这种情况不能发生,最少须要冊除多少条边。 也就是能够理解成:删去最少的边。使图中不存在奇圈。
二分图的定义:在无向图G中,至少有两个点且假设存在回路。那么回路必须为偶回路。 这样才是二分图。
所以依据定义可知:把n个点分成两部分,每一部分内的点集随意两点不相连。把相连的边就冊除。这种分法有2^n种。 最后找出冊除边数最少的就是所要求的。
#include<stdio.h>
#include<queue>
#include<string.h>
#include<iostream>
using namespace std;
int map[20][20],n;
int deletEdg(int k)
{
int ans=0;
for(int i=0;i<n;i++)
for(int j=i+1;j<n;j++)
{
if((k&(1<<i))==0&&(k&(1<<j))==0)ans+=map[i][j];//在同一部分的点它们相连的边数所有冊除
else if((k&(1<<i))!=0&&(k&(1<<j))!=0)ans+=map[i][j];
}
return ans;
}
int main()
{
int m,t,a,b;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
memset(map,0,sizeof(map));
while(m--)
{
scanf("%d%d",&a,&b);
map[a][b]++; map[b][a]++;//必须这样才干对
}
int MIN=99999999;
if(n==0||m==0)printf("0\n");
else{
for(int k=1;k<(1<<n);k++)//把n个数分成两部分有2^n种状态,每种状态为k,在该状态和第i位同为0的为第一部分,同为1的为还有一部分
{
int t=deletEdg(k);
if(t<MIN)MIN=t;
}
printf("%d\n",MIN);
}
}
}

版权声明:本文博客原创文章。博客,未经同意,不得转载。

hdu3118Arbiter (使用二分图的定义,枚举每个状态)的更多相关文章

  1. c# 枚举的定义,枚举的用法,获取枚举值

    1.定义枚举类型 public enum Test { 男 = , 女 = } 2.获取枚举值 public void EnumsAction() { var s = Test.男;//男 var a ...

  2. swift 定义枚举和结构体 及使用

    //定义枚举 enum MapDirection { case North case South case East case West func simpleDescription() -> ...

  3. Java分享笔记:自定义枚举类 & 使用enum关键字定义枚举类

    在JDK1.5之前没有enum关键字,如果想使用枚举类,程序员需要根据Java语言的规则自行设计.从JDK1.5开始,Java语言添加了enum关键字,可以通过该关键字方便地定义枚举类.这种枚举类有自 ...

  4. Effective Objective-C 2.0 — 第五条用枚举表示状态、选项、状态码 (未看完)

    枚举是一种常量命名方式.某个对象所经历的各种状态就可以定义为一个简单的枚举集.(enumeration set) 编译器会为枚举分配一个独有的编号,从0开始,每个枚举递增1.实现枚举所用的数据类型取决 ...

  5. [HDU5727]Necklace(二分图最大匹配,枚举)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5727 题意:有N个阴珠子和N个阳珠子,特定序号的阴阳珠子放在一起会让阳珠子暗淡.现在问排放成一个环,如 ...

  6. 利用DescriptionAttribute定义枚举值的描述信息 z

    System.ComponentModel命名空间下有个名为DescriptionAttribute的类用于指定属性或事件的说明,我所调用的枚举值描述信息就是DescriptionAttribute类 ...

  7. BZOJ1688|二进制枚举子集| 状态压缩DP

    Disease Manangement 疾病管理 Description Alas! A set of D (1 <= D <= 15) diseases (numbered 1..D) ...

  8. HDU 4462Scaring the Birds(枚举所有状态)

    Scaring the Birds Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  9. Qt-QML-ComboBox-自定义,实现状态表示,内容可以动态正价,使用ListModel

    哎呀呀呀, 问:杀死一个程序员一个程序要需要进步? 答:改三次需求 我感觉我就要再这需求的变更中被杀死了.不管怎么说,总是要跟着需求走的的,客户才是第一么(要不是因为钱,我才不会了) 下面先上个效果 ...

随机推荐

  1. Fragment为载体可自己主动布局的CardView(GitHub上写开源项目初体验)

    转载请注明本文出自大苞米的博客(http://blog.csdn.net/a396901990),谢谢支持! 开篇废话: 前些天一直在看Android5.0 的Material Desgin,里面新增 ...

  2. 神经网络 vs 大脑

    海马区域(负责记忆的关键区域) 0. 常见概念 神经递质:neurotransmitter 在突触传递中是担当"信使"的特定化学物质.简称递质. 重要的神经递质有:乙酰胆碱: 1. ...

  3. matplotlib学习之颜色样式

    一.颜色 1.内建八种默认颜色 蓝色 - 'b' 绿色 - 'g' 红色 - 'r' 青色 - 'c' 品红 - 'm' 黄色 - 'y' 黑色 - 'k' 白色 - 'w' 2.灰度 plt.plo ...

  4. 初步安装git使用命令配置电脑中的git关联的账户

    原文地址 https://www.jianshu.com/p/39684a3ad4fa 出现问题 当我们初步使用git的时候,会报一些出乎预料的错误,比如:报错:fatal: unable to au ...

  5. jboss-as-7.1.1.Final与jdk1.8不兼容解决方案

    今天在安装1.8电脑上装了jboss7.1.1,配置好了运行的时候就是无法启动,最后得出答案是:jboss-as-7.1.1.Final与jdk1.8不兼容 1.如果你的电脑安装了jdk1.8,那么在 ...

  6. 单选框radio改变事件详解(用的jquery的radio的change事件)

    单选框radio改变事件详解(用的jquery的radio的change事件) 一.总结 1.用的jquery的radio的change事件:当元素的值发生改变时,会发生 change 事件,radi ...

  7. jquery修改获取radio的选中项

    <input id="txtBeginDate" onclick="$('#divDate').css({'top':$('#txtBeginDate').offs ...

  8. linux中竖线'|',双竖线‘||’,&和&&的意思

    对于初学者来说这几个意思可能只知道其中几个的意思,下面我们来看一下. 1.竖线'|' ,在linux中是作为管道符的,将'|'前面命令的输出作为'|'后面的输入.举个例子 [18066609@root ...

  9. java.sql.SQLException:Column count doesn&#39;t match value count at row 1

    1.错误描写叙述 java.sql.SQLException:Column count doesn't match value count at row 1 2.错误原因     在插入数据时,插入的 ...

  10. php实现求二进制中1的个数(右移、&、int32位)(n = n & (n - 1);)

    php实现求二进制中1的个数(右移.&.int32位)(n = n & (n - 1);) 一.总结 1.PHP中的位运算符和java和c++一样 2.位移运算符看箭头方向,箭头向左就 ...