题意:

有一个老师想组织学生出去旅游,为了避免他们之间有情侣产生,他制定了一系列的条件,满足这些条件之一,那么这些人理论上就不会成为情侣:

身高相差40cm;性别相同;喜欢的音乐风格不同;最喜欢的运动相同。

给出若干个学生的身高,性别,喜欢的音乐风格和喜欢的运动,问最多有多少人可以出去。

思路:

对于两个人,如果以上所有条件都不满足,那么就在他们之间连边,说明他们不能同时去。

问题就转化成了求一个二分图的最大独立集。(独立集是两两之间不存在边的点的集合,最大顾名思义)

最大独立集 = 点数- 最小点覆盖  = 点数 – 最大匹配

匈牙利算法,复杂度O(n^3)。

代码:

 #include <stdio.h>
#include <iostream>
#include <string>
#include <string.h>
#include <vector>
using namespace std; const int N = ; vector<int> g[N];
int link[N];
bool vis[N]; struct node
{
int hei;
string sex,music,sport; node(int a,string b,string c,string d)
{
hei = a;
sex = b;
music = c;
sport = d;
}
}; vector<node> ns; bool dfs(int u)
{
for (int i = ;i < g[u].size();i++)
{
int v = g[u][i]; if (!vis[v])
{
vis[v] = ; if (link[v] == - || dfs(link[v]))
{
link[v] = u;
link[u] = v; return true;
}
}
} return false;
}
int solve(int n)
{
int cnt = ; memset(link,-,sizeof(link)); for (int i = ;i < n;i++)
{
if (link[i] == -)
{
memset(vis,,sizeof(vis));
if (dfs(i)) cnt++;
}
} return cnt;
} int mabs(int x)
{
return x >= ? x : -x;
} int main()
{
int t; scanf("%d",&t); while (t--)
{
int n; scanf("%d",&n); ns.clear(); for (int i = ;i < n;i++)
{
g[i].clear();
int a;
string b,c,d; cin >> a >> b >> c >> d; ns.push_back(node(a,b,c,d));
} for (int i = ;i < n;i++)
{
for (int j = i + ;j < n;j++)
{
bool f = ; if (mabs(ns[i].hei - ns[j].hei) > ) f = ;
if (ns[i].sex == ns[j].sex) f = ;
if (ns[i].music != ns[j].music) f = ;
if (ns[i].sport == ns[j].sport) f = ; if (!f)
{
g[i].push_back(j);
g[j].push_back(i);
}
}
} int ans = solve(n); printf("%d\n",n - ans);
} return ;
}

uvalive 3415 Guardian Of Decency的更多相关文章

  1. UVALive 3415 Guardian of Decency(二分图的最大独立集)

    题意:老师在选择一些学生做活动时,为避免学生发生暧昧关系,就提出了四个要求.在他眼中,只要任意两个人符合这四个要求之一,就不可能发生暧昧.现在给出n个学生关于这四个要求的信息,求老师可以挑选出的最大学 ...

  2. Guardian of Decency UVALive - 3415 最大独立集=结点数-最大匹配数 老师带大学生旅游

    /** 题目:Guardian of Decency UVALive - 3415 最大独立集=结点数-最大匹配数 老师带大学生旅游 链接:https://vjudge.net/problem/UVA ...

  3. Guardian of Decency(二分图)

    Guardian of Decency Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submi ...

  4. 训练指南 UVALive - 3415(最大点独立集)

    layout: post title: 训练指南 UVALive - 3415(最大点独立集) author: "luowentaoaa" catalog: true mathja ...

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

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

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

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

  7. uva 12083 Guardian of Decency (二分图匹配)

    uva 12083 Guardian of Decency Description Frank N. Stein is a very conservative high-school teacher. ...

  8. poj——2771 Guardian of Decency

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

  9. Guardian of Decency UVALive - 3415(最大独立集板题)

    老师在选择一些学生做活动时,为避免学生发生暧昧关系,就提出了四个要求.在他眼中,只要任意两个人符合这四个要求之一,就不可能发生暧昧.现在给出n个学生关于这四个要求的信息,求老师可以挑选出的最大学生数量 ...

随机推荐

  1. unity 2d游戏 按y坐标排序子对象

    List<Transform> objs = new List<Transform>(); for (int i = 0; i < transform.childCoun ...

  2. 【Python爬虫】PyQuery解析库

    PyQuery解析库 阅读目录 初始化 基本CSS选择器 查找元素 遍历 获取信息 DOM操作 伪类选择器 PyQuery 是 Python 仿照 jQuery 的严格实现.语法与 jQuery 几乎 ...

  3. 31-ADC模拟/数字转换

    31-ADC模拟/数字转换 (1).ADC的IO分配

  4. linux 修改centos7的网卡ens33修改为eth0

    Linux 操作系统的网卡设备的传统命名方式是 eth0.eth1.eth2等,而 CentOS7 提供了不同的命名规则,默认是基于固件.拓扑.位置信息来分配.这样做的优点是命名全自动的.可预知的,缺 ...

  5. 如何在js中将统计代码图标隐藏

    建站时我们都会加一下网站统计,方便把控内容的内容的运营.大部分站长安装的站点统计是第三方统计代码,js形式的,很少用以服务器日志为基础分析的统计.(当然能通过网站日志来分析网站的运营者比一般的站长水平 ...

  6. Windows server 2016 支持容器 ,安装docker 搭建Ubuntu+hadoop (docker为服务器)

    一.Windows server 2016 是肯定要安装的, 关于如何启动容器功能那就是控制面板中增加与删除里面的启用了,很多地方可以百度到 二. 安装Ubuntu hadoop 等  待续 注意: ...

  7. Vue+typescript报错项

    39:1 Unable to resolve signature of class decorator when called as an expression. Type '<VC exten ...

  8. LVS+Keepalived高可用部署

    一.LVS+Keepalived高可用部署 一.keepalived节点部署 1.安装keepalived yum install keepalived ipvsadm -y mkdir -p /op ...

  9. Python处理Excel和PDF文档

    一.使用Python操作Excel Python来操作Excel文档以及如何利用Python语言的函数和表达式操纵Excel文档中的数据. 虽然微软公司本身提供了一些函数,我们可以使用这些函数操作Ex ...

  10. Cpython解释器下实现并发编程——多进程、多线程、协程、IO模型

    一.背景知识 进程即正在执行的一个过程.进程是对正在运行的程序的一个抽象. 进程的概念起源于操作系统,是操作系统最核心的概念,也是操作系统提供的最古老也是最重要的抽象概念之一.操作系统的其他所有内容都 ...