http://poj.org/problem?id=2771

题意:

一个老师想带几个同学出去,但是他怕他们会谈恋爱,所以带出去的同学两两之间必须满足如下条件之一:

①身高差大于40  ②同性 ③喜欢的音乐风格不同 ④喜欢的运动相同

思路:

每两个人之间进行判断,如果不满足上面4个之一,则连一条线,说明他们是不能同时带出去的。然后找一个最大匹配,说明这几对中每队只能带出去一人,这样答案就很明显了。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std; const int maxn=+; int n; struct node
{
int height;
char sex;
char music[];
char sport[];
}a[maxn]; int g[maxn][maxn];
int vis[maxn];
int match[maxn]; bool judge(int i,int j)
{
if(abs(a[i].height-a[j].height)> || a[i].sex == a[j].sex || strcmp(a[i].music,a[j].music)||!strcmp(a[i].sport,a[j].sport)) return true;
return false;
} bool dfs(int x)
{
for(int i=;i<n;i++)
{
if(!vis[i] && g[x][i])
{
vis[i]=;
if(match[i]==- || dfs(match[i]))
{
match[i]=x;
return true;
}
}
}
return false;
} int main()
{
//freopen("D:\\txt.txt","r",stdin);
int T;
scanf("%d",&T);
while(T--)
{
memset(g,,sizeof(g));
scanf("%d",&n);
for(int i=;i<n;i++)
{
cin>>a[i].height>>a[i].sex>>a[i].music>>a[i].sport;
}
for(int i=;i<n;i++)
for(int j=;j<n;j++)
{ if(i==j) continue;
if(!judge(i,j)) g[i][j]=;
}
int ans=;
memset(match,-,sizeof(match));
for(int i=;i<n;i++)
{
memset(vis,,sizeof(vis));
{
if(dfs(i)) ans++;
}
}
cout<<n-ans/<<endl;
}
}

POJ 2771 Guardian of Decency的更多相关文章

  1. poj——2771 Guardian of Decency

    poj——2771    Guardian of Decency Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 5916   ...

  2. POJ 2771 Guardian of Decency 【最大独立集】

    传送门:http://poj.org/problem?id=2771 Guardian of Decency Time Limit: 3000MS   Memory Limit: 65536K Tot ...

  3. POJ 2771 Guardian of Decency (二分图最大点独立集)

    Guardian of Decency Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 6133   Accepted: 25 ...

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

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

  5. poj 2771 Guardian of Decency 解题报告

    题目链接:http://poj.org/problem?id=2771 题目意思:有一个保守的老师要带他的学生来一次短途旅行,但是他又害怕有些人会变成情侣关系,于是就想出了一个方法: 1.身高差距   ...

  6. POJ 2771 Guardian of Decency(求最大点独立集)

    该题反过来想:将所有可能发生恋爱关系的男女配对,那么可以带出去的人数应该等于这个二分图的最大独立集 先要做一下预处理,把不符合要求的双方先求出来, company[i][j]表示i.j四个标准都不符合 ...

  7. UVA 12083 POJ 2771 Guardian of Decency

    /* http://acm.hust.edu.cn/vjudge/contest/view.action?cid=71805#problem/C */ 性质: [1]二分图最大点独立数=顶点数-二分图 ...

  8. poj 2771 Guardian of Decency(最大独立数)

    题意:人与人之间满足4个条件之一即不能成为一对(也就说这4个条件都不满足才能成为一对),求可能的最多的单身人数. 思路:把男女分为两部分,接下来就是二分图的匹配问题.把能成为一对的之间连边,然后求出最 ...

  9. POJ——T2271 Guardian of Decency

    http://poj.org/problem?id=2771 Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 5932   A ...

随机推荐

  1. JS判断当前是否是IE浏览器,并返回时IE几?

    原文参考: https://www.cnblogs.com/liuyanxia/p/5855760.html 具体代码示例: 这里返回的是:如果不是IE浏览器返回 -1 ,返回 7/8/9/10/11 ...

  2. C语言实现日历输出

    这个还是挺实用的.... 头文件: #ifndef MAIN_H #define MAIN_H #include "stdio.h" #include "math.h&q ...

  3. Tomcat 400错误 问题集锦

    1.前后台参数类型不一致 上图错误提示就是客户端发送的请求不能找到你的具体的页面或者地址,这是Spring MVC抛出的错误,这样我们就要进行参数的检查,一定是JSP提交的参数和Controller里 ...

  4. 170609、Nginx配置文件详细说明

    在此记录下Nginx服务器nginx.conf的配置文件说明, 部分注释收集与网络. #运行用户 user www-data; #启动进程,通常设置成和cpu的数量相等 worker_processe ...

  5. python问答模块

    """ 该模块功能:获取用户的输入文本,通过输入文本和数据库中的关键主题文本相比较, 获取最佳的回答内容 """ import xlrd i ...

  6. Linux下手工卸载11.2 RAC(非MOS的deinstall方法)

    思路来自于经典的<How to Proceed From a Failed 10g or 11.1 Oracle Clusterware (CRS) Installation (Doc ID 2 ...

  7. Solutions for common Android development problems with the Eclipse IDE- Tutorial

    Table of Contents 1. Solving typical Android development problems 1.1. Clean Project 1.2. android.co ...

  8. 【asm】64位编译32位汇编需要注意的

    汇编语言在32位和64位下有区别    32位的汇编在代码前增加.code32    as可以通过--32指定生成32位汇编 在64位系统下ld链接生成32位程序:    ld: i386 archi ...

  9. 用MongoDB取代RabbitMQ(转)

    原文:http://blog.nosqlfan.com/html/3223.html RabbitMQ是当成应用比较广泛的队列服务系统,其配套的客户端和监控运维方案也比较成熟.BoxedIce的队列服 ...

  10. gb28181的SPVMN测试环境搭建以及设备端和服务器的具体实现

    1.GB/T28181开发1之SPVMN(1.0.0.1)环境搭建 https://blog.csdn.net/hiwubihe/article/details/82910685 2.SPVMN 视频 ...