摘要: 题目链接http://codeforces.com/problemset/problem/216/B 题意:有一群人要踢足球,但是在这些人中有几对人存在敌对的关系,要求每个队的人数相等并且同一个队中不存在互为敌对关系的人,每个人最多只会讨厌两个人,如果a讨厌b,那么b也会讨厌a,问你至少有多少人不能参加比赛。 并查集的灵活应用: 我们先把存在敌对关系的人之间连一条边,通过并查集把他们放在一个集合里,每次加入一条边时先判断这一条边的两点是否已存在同一个集合里,如果是,那么就构成了环,注意题目所说的每个人最多只会讨厌两个人,自己画画图就知道了,对环进行0,1,染色,可知如果环里面的人数为奇数,.. 阅读全文
posted @ 2013-03-15 19:51 zlyblog 阅读(330) 评论(0) 推荐(0)
摘要: 证明最大匹配=最小点集覆盖http://blog.csdn.net/wmn_wmn/article/details/7275648Sample Input4 4*.*..******...*.Sample Output4题意:有一块地,由于下雨,使部分面积出现泥泞,但牛只吃干净的草,现在想把出现泥泞的地方用木板铺盖上,这样牛的蹄子就不会因为踩到泥泞的地方弄脏草地上的草;一个n行m列的矩阵,"*“代表泥泞的土地,”.“代表草地,求最少覆盖的木板个数。注意:木板宽始终为1,长不限制;求最小覆盖=最大匹配;解析:这里我用0表示草地,则按行来铺木板,最有个数是51 0 2 0 0 3 3 3 阅读全文
posted @ 2012-08-03 20:35 zlyblog 阅读(232) 评论(0) 推荐(0)
摘要: 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2255[KM算法的几种转化]KM算法是求最大权完备匹配,如果要求最小权完备匹配怎么办?方法很简单,只需将所有的边权值取其相反数,求最大权完备匹配,匹配的值再取相反数即可。KM算法的运行要求是必须存在一个完备匹配,如果求一个最大权匹配(不一定完备)该如何办?依然很简单,把不存在的边权值赋为0。KM算法求得的最大权匹配是边权值和最大,如果我想要边权之积最大,又怎样转化?还是不难办到,每条边权取自然对数,然后求最大和权匹配,求得的结果a再算出e^a就是最大积匹配。至于精度问题则没有更好的办法了。(详细关于 阅读全文
posted @ 2012-08-03 20:08 zlyblog 阅读(276) 评论(0) 推荐(0)
摘要: InputThere will be multiple input cases.Each test case begins with two integers n, k. n is the number of rows and columns of the balloons (1 <= n <= 100), and k is the times that ginving to each student(0 < k <= n).Follow a matrix A of n*n, where Aij denote the color of the ballon in the 阅读全文
posted @ 2012-08-02 15:37 zlyblog 阅读(203) 评论(0) 推荐(0)
摘要: View Code 1 #include<stdio.h> 2 #include<string.h> 3 int t,n,m,num,map[1001][1001],a[1001],b[1001]; 4 int dfs(int x) 5 { 6 int i; 7 for(i=1;i<=m;i++) 8 { 9 if(map[x][i]&&b[i]==0)//对其进行覆盖10 {11 b[i]=1;12 if(a[i]==-1||dfs(a[i]))13 {14 ... 阅读全文
posted @ 2012-08-02 14:45 zlyblog 阅读(363) 评论(0) 推荐(0)
摘要: 并查集,欧拉回路View Code 1 #include<stdio.h> 2 #include<string.h> 3 #include<stdlib.h> 4 int n,len1; 5 char s[1005]; 6 int a[30],b[30]; 7 int set[30]; 8 int find(int x) 9 {10 if(x!=set[x])11 set[x]=find(set[x]);12 return set[x];13 }14 void met()15 {16 int i,x,y;17 for(i=1;i<=n;i++)... 阅读全文
posted @ 2012-08-01 17:13 zlyblog 阅读(194) 评论(0) 推荐(0)
摘要: 这个题主要有个小细节就是n=0时,应该输出1;这里给出两种方法:View Code 1 #include<stdio.h> 2 #include<string.h> 3 #include<stdlib.h> 4 #define N 10000005 5 int set[N],b[100005]; 6 int a[100005]; 7 int s[100005]; 8 int find(int x) 9 {10 if(x==set[x])11 return x;12 else13 set[x]=find(set[x]);14 }15 int ma... 阅读全文
posted @ 2012-08-01 15:16 zlyblog 阅读(200) 评论(0) 推荐(0)
摘要: 跟小希的迷宫有些相似。但却不知道为什么那些做法放这里就超时了。……View Code 1 2 #include <iostream> 3 #include <string.h> 4 #include <string> 5 #include <cstdio> 6 using namespace std; 7 int leftt[10005],rightt[10005],father[10005]; 8 int find(int x){ 9 if(father[x]==-1)10 return x;11 return find(father[x]); 阅读全文
posted @ 2012-08-01 10:58 zlyblog 阅读(205) 评论(0) 推荐(0)
摘要: View Code 1 #include<stdio.h> 2 #include<iostream> 3 using namespace std; 4 int main() 5 { 6 int n; 7 loop: 8 while(scanf("%d",&n)!=-1) 9 {10 int i,j,k;11 for(i=1;i<100;i++)//题目告诉测试实例不超过10000,也就意味着循环不超过10012 {13 for(j=1;j<100;j++)14 ... 阅读全文
posted @ 2012-07-31 20:54 zlyblog 阅读(213) 评论(0) 推荐(0)
摘要: View Code 1 #include <stdio.h> 2 int main() 3 { 4 int z, p, n; 5 scanf("%d", &z); 6 while (z-- != 0) 7 { 8 scanf("%d", &n); 9 p = 0;10 while (n%2== 0)11 {12 ++p;13 n=n/2;14 }15 printf("%d %d\n", n, p);16 }17... 阅读全文
posted @ 2012-07-31 16:55 zlyblog 阅读(110) 评论(0) 推荐(0)