Poj(2771),最大独立集
题目链接:http://poj.org/problem?id=2771
Time Limit: 3000MS | Memory Limit: 65536K | |
Total Submissions: 5517 | Accepted: 2322 |
Description
- Their height differs by more than 40 cm.
- They are of the same sex.
- Their preferred music style is different.
- Their favourite sport is the same (they are likely to be fans of different teams and that would result in fighting).
So, for any two persons that he brings on the excursion, they must
satisfy at least one of the requirements above. Help him find the
maximum number of persons he can take, given their vital information.
Input
first line of the input consists of an integer T ≤ 100 giving the number
of test cases. The first line of each test case consists of an integer N
≤ 500 giving the number of pupils. Next there will be one line for each
pupil consisting of four space-separated data items:
- an integer h giving the height in cm;
- a character 'F' for female or 'M' for male;
- a string describing the preferred music style;
- a string with the name of the favourite sport.
No string in the input will contain more than 100 characters, nor will any string contain any whitespace.
Output
Sample Input
2
4
35 M classicism programming
0 M baroque skiing
43 M baroque chess
30 F baroque soccer
8
27 M romance programming
194 F baroque programming
67 M baroque ping-pong
51 M classicism programming
80 M classicism Paintball
35 M baroque ping-pong
39 F romance ping-pong
110 M romance Paintball
Sample Output
3
7
Source
#include <stdio.h>
#include <string.h>
#include <math.h> bool maps[][];
bool use[];
int match[]; struct Stu {
int h;
char sex[];
char music[];
char sport[];
}mans[],womans[]; int nman,nwoman; bool judge(Stu a,Stu b)
{
if(strcmp(a.music,b.music)) return false;
if(!strcmp(a.sport,b.sport)) return false;
if(fabs((a.h-b.h)*1.0)>) return false;
return true;
} bool DFS(int u)
{
for(int i=;i<nwoman;i++)
{
if(!use[i]&&maps[u][i])
{
use[i] = true;
if(match[i]==-||DFS(match[i]))
{
match[i] = u;
return true;
}
}
}
return false;
} int main()
{
int t;
scanf("%d",&t);
while(t--)
{
memset(maps,false,sizeof(maps));
memset(match,-,sizeof(match));
int num;
nman = ;
nwoman = ;
scanf("%d",&num);
for(int i=;i<num;i++)
{
int height;
char sex[];
char musics[];
char sports[];
scanf("%d%s%s%s",&height,sex,musics,sports);
if(sex[]=='M')
{
mans[nman].h = height;
strcpy(mans[nman].sex,sex);
strcpy(mans[nman].music,musics);
strcpy(mans[nman++].sport,sports);
}
if(sex[]=='F')
{
womans[nwoman].h = height;
strcpy(womans[nwoman].sex,sex);
strcpy(womans[nwoman].music,musics);
strcpy(womans[nwoman++].sport,sports);
}
} for(int i=;i<nman;i++)
{
for(int j=;j<nwoman;j++)
{
if(judge(mans[i],womans[j]))
maps[i][j] = true;
}
} int ans = ;
for(int i=;i<nman;i++)
{
memset(use,false,sizeof(use));
if(DFS(i))
ans++;
}
printf("%d\n",num-ans); }
return ;
}
Poj(2771),最大独立集的更多相关文章
- poj 2771 最大独立集
这道题又无耻的抄袭了别人的代码. 刚开始以为是最大匹配,把条件不相符的人连一起,然后求最大匹配,感觉麻烦,然后看了别人的解题报告,是把相符的人连一起,然后减去,其实就是最大独立集. 最大独立集=|G| ...
- POJ 2771 最大独立集 匈牙利算法
(为什么最大独立集的背景都是严打搞对象的( _ _)ノ|壁) 思路:匈牙利算法 没什么可说的-- // by SiriusRen #include <cstdio> #include &l ...
- poj——2771 Guardian of Decency
poj——2771 Guardian of Decency Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 5916 ...
- POJ 2771 Guardian of Decency 【最大独立集】
传送门:http://poj.org/problem?id=2771 Guardian of Decency Time Limit: 3000MS Memory Limit: 65536K Tot ...
- POJ 2771 Guardian of Decency(最大独立集数=顶点数-最大匹配数)
题目链接: http://poj.org/problem?id=2771 Description Frank N. Stein is a very conservative high-school t ...
- POJ 2771 二分图(最大独立集)
Guardian of Decency Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 5244 Accepted: 21 ...
- Guardian of Decency POJ - 2771 【二分匹配,最大独立集】
Problem DescriptionFrank N. Stein is a very conservative high-school teacher. He wants to take some ...
- poj 2771 Guardian of Decency 解题报告
题目链接:http://poj.org/problem?id=2771 题目意思:有一个保守的老师要带他的学生来一次短途旅行,但是他又害怕有些人会变成情侣关系,于是就想出了一个方法: 1.身高差距 ...
- POJ 2771 Guardian of Decency
http://poj.org/problem?id=2771 题意: 一个老师想带几个同学出去,但是他怕他们会谈恋爱,所以带出去的同学两两之间必须满足如下条件之一: ①身高差大于40 ②同性 ③喜欢 ...
随机推荐
- 为benchmarksql的PostgreSQL java驱动进行升级
为benchmarksql的PostgreSQL java驱动进行升级[root@minion1 benchmarksql-4.1.0]# wget https://jdbc.postgresql.o ...
- ActionController::InvalidAuthenticityToken 解决办法(第二种尤其有效)
第一种: Ror代码 class FooController < ApplicationController protect_from_forgery :except => ...
- .NET: 防止多个应用程序同时开
用到了Mutex这个类,直接看代码~ using System; using System.Collections.Generic; using System.Linq; using System.W ...
- sqlserver 存储过程 以及统计整个数据库数据
drop proc test 删除存储过程 go 用于在 SSMS 和 SQLCMD 中将其之前的 T-SQL 语句作为一个批处理提交给 SQL Server 实例.GO 不是 T-SQL 语句,只 ...
- Node.js Express 获取request原始数据
app.use(bodyParser.json());客户端请求接口时如果指名请求头类型 为Content-Type=application/jsonbodyParser 会自动将 body 里的 j ...
- 线性表基本维护[ACM]
#include "iostream" #include "string" using namespace std; typedef struct node{ ...
- java post请求
package com.jfbank.loan.intf.util; import java.io.IOException;import java.util.ArrayList;import java ...
- Script to compile invalid objects in DB
REM: Script to compile invalid objects in DB after refreshing REM: REM:***************************** ...
- ionic之AngularJS扩展 移动开发(视图导航一)
目录: 内联模板 : script 路由机制 : 状态机 导航视图 : ion-nav-view 模板视图 : ion-view 导航栏 : ion-nav-bar 回退按钮 : ion-nav-ba ...
- JNI 回调小记
javah在eclipse中设置参数:location(javah.exe的位置)working dir(${project_loc}/src) -classpath .;./classes -d $ ...