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

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

// 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. Static variables in JavaScript

    function MyClass () { // constructor function var privateVariable = "foo"; //NO:obj.privat ...

  2. 【Oracle】ORA-38171: Insufficient privileges for SQL management object operation

    问题: 使用SQL PLAN MANAGEMENT的时候运行下面的存储过程报错. SYS@GOOD> conn scott/tiger Connected. SCOTT@GOOD> DEC ...

  3. 【Oracle】审计

    1.审计的功能:监控用户在database 的 action (操作) 2.审计分类: 1) session :在同一个session,相同的语句只产生一个审计结果(默认) 2) access : 在 ...

  4. In-Out Parameters inout keyword

    You write an in-out parameter by placing the inout keyword right before a parameter’s type. An in-ou ...

  5. MongoDB_可视化工具Robo 3T

    Robo 3T可以对MongoDB进行可视化操作. Robo 3T安装 官网下载地址:https://robomongo.org/ 进入官网,点击下载,Studio 3T功能更全面,基础功能是免费的, ...

  6. day25-2 random,os,sys模块

    目录 random 为什么要有random模块,random模块有什么用 os 为什么要有os模块,os模块有什么用 sys 为什么要有sys模块,sys模块有什么用 random import ra ...

  7. 路飞学城Python-Day59(第五模块思维导图)

  8. nyoj252-01串

    01串 时间限制:1000 ms  |  内存限制:65535 KB 难度:2 描述 ACM的zyc在研究01串,他知道某一01串的长度,但他想知道不含有"11"子串的这种长度的0 ...

  9. [Ynoi2019模拟赛]Yuno loves sqrt technology II

    题目大意: 给定一个长为\(n\)的序列,\(m\)次询问,每次查询一个区间的逆序对数. 32MB. 解题思路: 出题人题解 众所周知lxl是个毒瘤,Ynoi道道都是神仙题 二次离线莫队. 对于每个区 ...

  10. maven项目发布后访问jsp页面报错

    type Exception report message java.lang.NullPointerException description The server encountered an i ...