poj——2771 Guardian of Decency
Time Limit: 3000MS | Memory Limit: 65536K | |
Total Submissions: 5916 | Accepted: 2458 |
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
- 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
题意:现在有一个老师想带领他的学生出去郊游,但是他非常担心在郊游的过程中有些学生会发生恋爱关系,而他认为发生恋爱关系的可能性比较小的判断标准有以下四个,如果满足四个条件中的任何一个,即被他认为可能发生恋爱关系的可能性比较小:
1>两人身高的差距超过40cm;
2>两人性别相同;
3>两人所喜欢的音乐风格不同;
4>两人最喜爱的运动相同;
现在给出n个学生,并给出每个学生的信息(信息为:身高 性别 所喜欢的音乐风格 喜爱的运动),要求求解最大可以带出去郊游的学生数.
#include<cstdio> #include<cstdlib> #include<cstring> #include<iostream> #include<algorithm> #define N 510 using namespace std; char ch; bool vis[N]; int t,n,x,ans,gnum,bnum,pre[N],map[N][N]; struct nn {int h;char fm[10000];char fs[10000]; }girl[N],boy[N]; int read() {int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();}while(ch<='9'&&ch>='0'){x=x*10+ch-'0'; ch=getchar();}return x*f; } void add_edge() {for(int i=1;i<=bnum;i++)for(int j=1;j<=gnum;j++)if(!strcmp(boy[i].fm,girl[j].fm)&&strcmp(boy[i].fs,girl[j].fs)&&abs(boy[i].h-girl[j].h)<=40)map[i][j]=1; } int find(int x) {for(int i=1;i<=gnum;i++)if(!vis[i]&&map[x][i]){vis[i]=true;if(pre[i]==0||find(pre[i])){pre[i]=x;return 1;}}return 0; } int main() {t=read();while(t--){ans=0;bnum=0,gnum=0;memset(boy,0,sizeof(boy));memset(girl,0,sizeof(girl));memset(pre,0,sizeof(pre));memset(map,0,sizeof(map));n=read();for(int i=1;i<=n;i++){x=read(); scanf("%c",&ch);if(ch=='F') {girl[++gnum].h=x;cin>>girl[gnum].fm; cin>>girl[gnum].fs;}else {boy[++bnum].h=x;cin>>boy[bnum].fm;cin>>boy[bnum].fs;}}add_edge();for(int i=1;i<=bnum;i++){memset(vis,0,sizeof(vis));if(find(i)) ans++;}printf("%d\n",n-ans);}return 0; }
转载于:https://www.cnblogs.com/z360/p/7107170.html
poj——2771 Guardian of Decency相关推荐
- POJ-2771 Guardian of Decency 最大独立子集
不能恋爱问题. 代码如下: #include <cstdlib>#include <cstdio>#include <cstring>using namespace ...
- UVA - 12083 Guardian of Decency (二分匹配)
题意:有N个人,已知身高.性别.音乐.运动.要求选出尽可能多的人,使这些人两两之间至少满足下列四个条件之一. 1.身高差>40 2.性别相同 3.音乐不同 4.运动相同 分析: 1.很显然 ...
- poj 2771 有点难度最大独立集
题意:一个老师要带一些学生去旅游 , 下面任意两个学生至少要满足下面一个条件: 1.身高相差要超过40cm 2.性别相同 3.最喜欢的音乐属于不同类型 4.最喜欢的体育比赛相同 解 法:我们首先这样来 ...
- 【转载】图论 500题——主要为hdu/poj/zoj
转自--http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...
- 【HDOJ图论题集】【转】
1 =============================以下是最小生成树+并查集====================================== 2 [HDU] 3 1213 How ...
- 一系列图论问题[转]
=============================以下是最小生成树+并查集====================================== [HDU] 1213 How Many ...
- 图论练习题(存起来练)
=============================以下是最小生成树+并查集====================================== [HDU] 1213 How Man ...
- ACM比赛经验、刷题记录及模板库总结(更新中)
前言 本文所提及的部分题目代码,可以在我的Github上找到 第一部分 经验分享及感受 第二部分 刷题记录 一.基础算法&程序语言 //strlen()函数的复杂度是O(n)要小心 //截取字 ...
- 网络流题集【夏天的风】
[HDU] 1532Drainage Ditches(基础) [最大流] 3549 Flow Problem(基础) [最大流] 3572 Task Schedule [最大流]任务 ...
最新文章
- mysql主从以及读写分离(科普)
- python简单的小程序_初学python的一些简单程序(1)
- git--分支管理:创建、合并、冲突解决
- 阿里P7/P8学习路线图——技术封神之路
- linux sed 测试文件夹,测试开发笔记二(Linux与Shell脚本)
- [BUUCTF-pwn]——pwnable_orw (ORW)
- jsp导入jstl标签库_EE JSP:使用JSTL标记库生成动态内容
- 第二十期:核心交换机的链路聚合、冗余、堆叠、热备份
- linux普通用户发送信号,Linux信号发送与作业控制
- 私有云为先 ZStack还在谋划一个更大的混合云世界
- 关键字Restrict
- linux之yum下载rpm包离线安装
- 6.3交换器(Exchangers)
- 小D课堂 - 零基础入门SpringBoot2.X到实战_第8节 数据库操作之整合Mybaties和事务讲解_34、SpringBoot整合Mybatis实操和打印SQL语句...
- 真的神了~无意中发现1500道的2021LeetCode算法刷题pdf笔记
- JAVA语言基础——基本语法
- 全国各主要省市经纬度
- matlab如何定义dmod函数,matlab中的dmod函数
- 前端面试题整理—ES6篇
- RE|Nginx-安装与配置(1)
热门文章
- 系统开出出现问题~~~\WINDOWS\SYSTEM32\CONFIG\SYSTEM 损坏或丢失无法开机
- c语言 strlower 将所有的字母转化为小写字母
- Asp.net 随记 Part1 (1- 30)
- 再谈HTTP2性能提升之背后原理—HTTP2历史解剖
- I.MX6 Android 5.1 纯Linux、U-Boot编译
- tar 解压缩命令详解
- 制作最小Linux系统并且让其在新的虚拟机上运行
- There is no isNullOrEmpty for collections in Guawa
- Linux 命令小汇总
- iOS load方法和initialize方法的异同