(为什么最大独立集的背景都是严打搞对象的( _ _)ノ|壁)

思路:匈牙利算法 没什么可说的……

// by SiriusRen
#include <cstdio>
#include <cstring>
using namespace std;
int cases,n,tot,ans,first[555],next[555555],v[555555],fa[555],vis[555];
struct Student{int n;char sex[2],music[105],sport[105];}stu[555];
void add(int x,int y){v[tot]=y,next[tot]=first[x],first[x]=tot++;}
bool check(int i,int j){
if(stu[i].n-stu[j].n>40||stu[i].n-stu[j].n<-40)return 0;
else if(stu[i].sex[0]==stu[j].sex[0])return 0;
else if(strcmp(stu[i].music,stu[j].music))return 0;
else if(!strcmp(stu[i].sport,stu[j].sport))return 0;
return 1;
}
bool dfs(int x){
for(int i=first[x];~i;i=next[i])
if(!vis[v[i]]){
vis[v[i]]=1;
if(!fa[v[i]]||dfs(fa[v[i]]))
{fa[v[i]]=x;return 1;}
}
return 0;
}
int main(){
scanf("%d",&cases);
while(cases--){
tot=ans=0,memset(fa,0,sizeof(fa)),memset(first,-1,sizeof(first));
scanf("%d",&n);
for(int i=1;i<=n;i++)scanf("%d%s%s%s",&stu[i].n,stu[i].sex,stu[i].music,stu[i].sport);
for(int i=1;i<=n;i++)for(int j=i+1;j<=n;j++)if(check(i,j))add(i,j),add(j,i);
for(int i=1;i<=n;i++){memset(vis,0,sizeof(vis));if(dfs(i))ans++;}
printf("%d\n",n-ans/2);
}
}

POJ 2771 最大独立集 匈牙利算法的更多相关文章

  1. POJ 3041.Asteroids-Hungary(匈牙利算法)

    Asteroids Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 23963   Accepted: 12989 Descr ...

  2. POJ 3041 Asteroids 匈牙利算法,最大流解法,行列为点 难度:1

    http://poj.org/problem?id=3041 #include <cstdio> #include <cstring> #include <vector& ...

  3. poj 1469 COURSES(匈牙利算法模板)

    http://poj.org/problem?id=1469 COURSES Time Limit: 1000MS   Memory Limit: 10000K Total Submissions:  ...

  4. poj 2771 最大独立集

    这道题又无耻的抄袭了别人的代码. 刚开始以为是最大匹配,把条件不相符的人连一起,然后求最大匹配,感觉麻烦,然后看了别人的解题报告,是把相符的人连一起,然后减去,其实就是最大独立集. 最大独立集=|G| ...

  5. POJ 3041 Asteroids | 匈牙利算法模板

    emmmmm 让你敲个匈牙利 #include<cstdio> #include<algorithm> #include<cstring> #define N 51 ...

  6. Poj(1466),最大独立集,匈牙利算法

    题目链接:http://poj.org/problem?id=1466 Girls and Boys Time Limit: 5000MS   Memory Limit: 10000K Total S ...

  7. POJ 2771 Guardian of Decency(最大独立集数=顶点数-最大匹配数)

    题目链接: http://poj.org/problem?id=2771 Description Frank N. Stein is a very conservative high-school t ...

  8. POJ:3041-Asteroids(匈牙利算法模板)

    传送门:http://poj.org/problem?id=3041 Asteroids Time Limit: 1000MS Memory Limit: 65536K Description Bes ...

  9. poj - 3041 Asteroids (二分图最大匹配+匈牙利算法)

    http://poj.org/problem?id=3041 在n*n的网格中有K颗小行星,小行星i的位置是(Ri,Ci),现在有一个强有力的武器能够用一发光速将一整行或一整列的小行星轰为灰烬,想要利 ...

随机推荐

  1. JavaScript实现延时提示框

    <html> <head> <meta charset="utf-8"> <title>无标题文档</title> &l ...

  2. JavaScript实现数字时钟功能

    <html> <head> <meta charset="utf-8"> <title>无标题文档</title> &l ...

  3. 性能问题解决案例01——sybase数据库内存问题

    最近湖南现场反馈问题,所有电子签章页面打不开文书(pdf格式),后台日志没报任何错误. 1.首先想到是签章的ocx控件问题,检查ocx控件安装,发现其他电脑也打不开文书,测试页面可以直接打开pdf文档 ...

  4. python安装Django需要环境

    Django==1.10.3 -e git+https://github.com/duoshuo/duoshuo-python-sdk.git#egg=duoshuo-python-sdk djang ...

  5. Vtk读取并显示保存图像

    (1):Vtk读取并显示图像:三种方法 转载:未知出处 转载:用VTK显示平面图片:http://blog.csdn.net/tonylk/article/details/464881 用到vtkJP ...

  6. (转)基于MVC4+EasyUI的Web开发框架经验总结(3)- 使用Json实体类构建菜单数据

    http://www.cnblogs.com/wuhuacong/p/3669708.html 最近花了不少时间在重构和进一步提炼我的Web开发框架上,力求在用户体验和界面设计方面,和Winform开 ...

  7. sql_1

    order by SELECT Company, OrderNumber FROM Orders ORDER BY Company DESC; SELECT Company, OrderNumber ...

  8. spring4+hibernate4+struts2环境搭建

    tomact配置请查看下面的文章 javaEE_maven_struts2_tomcat_first http://www.cnblogs.com/luotuoke/p/4543686.html po ...

  9. PhotoZoom Classic 7中的新功能

    众所周知PhotoZoom Classic是家庭使用理想的放大图像软件.目前很多用户还在使用PhotoZoom Classic 6,对于PhotoZoom Classic 7还是有点陌生.其实在6代衍 ...

  10. Pycharm 设置

    1:显示行号 打上对勾OK 2:设置作者 & 文件编码 3:选择切换Python的版本