2019-02-26-University Entrace Examination -ZOJ1023-稳定婚姻算法(变式)

【ZZULIOJ】1075: 聚餐人数统计 ZZULIOJ题解 1075: 聚餐人数统计 题目描述 马克思手稿中有这样一道趣味数学题:男人、女人和小孩总计n个人,在一家饭店里吃饭,共花了cost先令,每个男人各花3先令,每个女人各花2先令,每个小孩各花1先令,请用穷举法编程计算男人、女人和小孩各有几个。 输入 输入两个正整数,表示人数n和花费cost。 输出 若问题有解,则输出所有解,每行输出三个数据,代表男人、女人和小孩的人数,用空格分隔;若问题无解,则输出“No answer"。 样例输入 30 50 样例输出 0 20 1 阅读详情

ZOJ-1023-University Entrace Examination

Problem Description

There is a fierce competition among high-school graduates in Iran to pass the centralized nationwide university entrance examination. Ministry of Science, Research, and Technology has set up the Education Evaluation Organization (EEO) to take care of all aspects of this big exam. This year the EEO managed to select some 150,000 students to enter universities out of 1.4 million high school graduates participated in a tough 4.5 hours multiple-choice exam. This annual event is usually preceded by a multi-billion Rial business offering preparatory courses to enthusiastic students. A few weeks after the big exam day, each participant receives a score sheet, and a list of Field-Department-University (FDU), displaying each field of study in the universities锟斤拷 departments (e.g., the Software Engineering field of Computer Engineering department at Sharif University of Technology) along with their capacity for that year. The eligible participants (those who have scored enough to be allowed to declare their FDU priorities) fill out a priority indication form, and declare the FDUs they like to enter, in the order of their preference. The EEO processes the forms, and considering the total score, the participant锟斤拷s FDU priority list, and some other selection rules, enters the accepted participants锟斤拷 names in the list of each FDU, until all capacities are exhausted. Those who are not entered in a list are considered failed and may try again next year. Each accepted participant锟斤拷s name may be entered in only one list.

One of the interesting selection rules is to persuade participants to enter universities in the vicinity of their home towns. This is to help reduce the number of requests for staying in the university dormitories.
The selection process is so complex and so sensitive to many, that EEO has decided to hire the very best programmers in Iran to design a new selection algorithm and write a completely new program for what they have been doing for years. ACM programming contest is where these programmers can be found.

There are N students S1 to SN , and M items F1 to FM , each representing one of the FDUs. There are also a number of geographic regions. For each participant, the total score, the geographic region where his/her high school diploma was awarded, and a priority list of his/her wanted FDUs are available. For each FDU, the geographic region where the corresponding university is located, and its capacity for that year is recorded.

Write a program to compute the list of accepted students with the FDU they can enter to, given the above list of input data. Your program must abide with the following rules:

1. (Local student selection rule) Suppose two students A and B have both selected F in their priority lists and F is in region R. Also suppose that score of A is greater than B's score. Then, if B is from region R (local) and A is from other regions (non-local), and B's score is greater than 70% of A's score, then B has priority over A to enter F. In all other cases A has priority over B to enter F.

2. (Fairness rule) Students should be treated according to their priority list of FDUs. That is, an accepted student will be accepted to the first possible FDU he/she can enter.

Note: We assume that scores are all different integer values.


Input

The first line of the input contains a single integer t (1 <= t <= 10), the number of test cases, followed by the input data for each test case. The first line of each test case contains N (1 <= N <= 150) and M (1 <= M <= 50) followed by N lines, each for one student. The format of these lines is Ri, Mi, K, Fi1, 锟斤拷, FiK in this order. In this line, that is for student i, Ri is his/her region number, Mi is his/her score in the entrance exam, K is the number of FDUs in his/her priority list (0 <= K <= M), and his/her priority list containing the FDU numbers in order of interest. Then there are M lines, one for each FDU. Each line contains Ri, and Ci in that order, which respectively is region number of Fi (the ith FDU) and the capacity of Fi. Note that region numbers are arbitrary integers.

Output

Outputs for different test cases are separated by exactly one blank line. For each test case, you should write N lines, one for each of the N students. If student i has been accepted to FDU Fj, then ith line should contain j, and not accepted, if that student has not been accepted in any FDU of his/her interest.


Sample Input

1
9 2
1 100 2 1 2
2 80 2 2 1
1 90 1 1
2 40 1 2
2 50 1 1
1 60 1 2
2 75 1 1
1 95 1 1
2 30 1 2
1 3
2 4

Sample Output

1
2
1
2
not accepted
2
not accepted
1
2

问题简述

题意:对于给定的n个学生和m所学校,已知学生i的k个期望学校和排名,每个学生的地理位置和分数,以及每所学校的容纳上限,试在满足条件下使其形成稳定匹配。

条件:

1.假设学生a,b都有期望学校x,对于x而言,如果a来自x的区域,b不来自x的区域,且a的分数大于70%的b的分数,那么x更倾向于选择a;在其他情况下,x总是选择分数高的学生。

2.一个被录取的学生应该进入到他第一个可能进入的学校。(按优先列表来选择)

难点:类似于稳定婚姻算法,但是学生(男生)可能匹配不到学校,学校(女生)可能匹配多个学生。

所以循环终止条件应改为:任何一个学生或者有匹配,或者已经对所有倾向列表上的学校表白过

条目检索:稳定婚姻算法

输入输出

输入:无难度,t组数据,n个学生,m所学校,n行学生信息(所在区域,分数,期望学校数k,k所期望学校编号),m行学校信息(所在区域,容纳上限)

输出:无难度

使用模板(稳定婚姻算法)

struct Gale_Shapley{
	static const int N=60;
	int n;
	int fg;
	int woman[N][N];        //第i个girl对编号j的boy的好感排位 
	int man[N][N];          //第i个boy第j喜欢的girl 
	int man_match[N],woman_match[N];    //已匹配的男女 
	int p[N];               //第i个boy已经表白的人数 
	void solve(){
		for(int i=0;i<N;i++)p[i]=1;//初始化每个男生表白1次
		memset(man_match,0,sizeof(man_match));
		memset(woman_match,0,sizeof(woman_match));
		fg=true;
        //fg标记当前是否还有人没有匹配
		while(fg){
			fg=false;
			for(int i=1;i<=n;i++){//男生i进行表白
				if(!man_match[i]){//如果没有匹配
					int t=man[i][p[i]++];//男生向下一个倾慕对象表白
					if(!woman_match[t]){//如果女生没有匹配,直接配对
						man_match[i]=t;
						woman_match[t]=i;
					}else if(woman[t][woman_match[t]]>woman[t][i]){
                        //如果女生觉得这个男生比自己现在的更好
						man_match[woman_match[t]]=0;    //抛弃之前的
						man_match[i]=t;
						woman_match[t]=i;
					}
					fg=true;
				}
			}
		}
	}
}T;

AC代码

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define N 200
using namespace std;
typedef struct student{
	int id;            //学生编号 
	int area;          //所在区域 
	int score;         //分数 
	int k;             //中意学校数 
}student;
typedef struct school{
	int area;          //区域 
	int v;             //容量 
}school;
typedef struct matchs{
	int cnt;           //容纳学生数
	int match[N];      //列表
}matchs;
student stu[N];        //学生信息
school sch[N];         //学校信息
matchs fmat[N];        //学校匹配的学生数,和学生列表
int mmat[N];           //学生匹配的学校
int man_match[N][N];   //学生i第j期望的学校
int woman_match[N][N]; //学校i对于学生j的倾向度
int vis[N];            //i是否已经全部表白过 
int p[N];              //当前i要向p[i]表白 
int n,m;               //n学生,m学校 
int rr;                //当前区域 

bool cmp_a(student a,student b){      //比较函数a
	if(a.area==rr&&b.area!=rr){
		if(fabs(a.score-0.7*b.score)<1e-6)return 0;
		else return a.score>0.7*b.score;
	}else if(a.area!=rr&&b.area==rr){
		if(fabs(b.score-0.7*a.score)<1e-6)return 1;
		else return b.score<0.7*a.score;
	}else{
		return a.score>b.score;
	}
}
bool cmp_b(student a,student b){      //比较函数b
	return a.id<b.id;
}

void read(){
	scanf("%d%d",&n,&m);
	int ri,mi,ki,ch;
	memset(man_match,0,sizeof(man_match));
	memset(woman_match,0,sizeof(woman_match));
	for(int i=1;i<=n;i++){
		scanf("%d%d%d",&ri,&mi,&ki);
		stu[i].id=i;
		stu[i].area=ri;
		stu[i].k=ki;
		stu[i].score=mi;
		for(int j=1;j<=ki;j++){
			scanf("%d",&ch);
			man_match[i][j]=ch;       //男生i第j喜欢的女生是ch 
		}
	}
	for(int i=1;i<=m;i++){
		scanf("%d%d",&sch[i].area,&sch[i].v);
	}
}
void getRank(){
	for(int i=1;i<=m;i++){
		rr=sch[i].area;
		sort(stu+1,stu+n+1,cmp_a);        //把学生按照学校i的区域排序
		for(int j=1;j<=n;j++){
			woman_match[i][stu[j].id]=j;  //学校i对于学生stu[j].id的倾向度为j
		}
	}
	sort(stu+1,stu+n+1,cmp_b);            //按照学生编号排序,即回归原状
}
void GS(){
	bool fg=1;
	memset(mmat,0,sizeof(mmat));
	for(int i=1;i<=n;i++){
		p[i]=1;
		vis[i]=0;
	}
	for(int i=1;i<=m;i++){
		fmat[i].cnt=0;
	}
	while(fg){
		fg=0;
		for(int i=1;i<=n;i++){            //每个学生进行表白 
			while(!mmat[i]&&!vis[i]){     //直到i匹配到学校,或者再也不能匹配到学校停止
				fg=1;
				if(p[i]>stu[i].k){        //如果i现在已经对所有倾向的学校表白过,则标记
					vis[i]=1;
					break;
				}
				int u=man_match[i][p[i]++];     //i当前想要表白的学校
				if(fmat[u].cnt<sch[u].v){       //如果u学校还有空余,表白成功 
					fmat[u].match[++fmat[u].cnt]=i;
					mmat[i]=u;
				}else if(fmat[u].cnt==sch[u].v){//如果u学校当前没有空余
					int worstrank=0;
					int worstid;
					for(int j=1;j<=fmat[u].cnt;j++){//找到u学校当前列表中最不喜欢的学生
						if(worstrank<woman_match[u][fmat[u].match[j]]){
							worstrank=woman_match[u][fmat[u].match[j]];
							worstid=j;
						}
					}
					if(worstrank>woman_match[u][i]){//如果i比最差的更好,则取代位置
                        //下面两行不能互换!!
                        //易错点
						mmat[fmat[u].match[worstid]]=0;
						fmat[u].match[worstid]=i;
						mmat[i]=u;
					}
				}
			}
		}
	}
	
}
int main(){
	int cases;
	scanf("%d",&cases);
	while(cases--){
		read();
		getRank();
		GS();
		for(int i=1;i<=n;i++){
			if(vis[i])printf("not accepted\n");
			else printf("%d\n",mmat[i]);
		}
		if(cases)printf("\n");
	}
	return 0;
}

参考链接

https://blog.youkuaiyun.com/secfly/article/details/50768559

https://blog.youkuaiyun.com/RaAlGhul/article/details/50686211

『杭电1368』University Entrance Examination Problem Description There is a fierce competition among high-school graduates in Iran to pass the centralized nationwide university entrance examination. Ministry of Science, Research, and Technology has set up the Education Evaluation Organization (EEO) 阅读详情

相关推荐

zzulioj部分题目答案(1101~1187、2113)

郑州轻工业大学在线评测系统(ZZULIOJ)部分答案。大一上学期自己做的,全部是c语言实现,不一定是最优解仅供参考。希望可以帮助到大家。

POJ 1075 University Entrance Examination 笔记

学校招生,本地学生优先。N个学生,M个学校。学生i,Ri学生的区域号,Mi分数,K志愿学校数,Fi1第一志愿,FiK第k志愿。学校i,Ri学校区域号,Ci学校i的容量。 招生规定: 学生A、B在相同志愿报了同一学校。A是外地,B是本地。A的分数*0.7于B的分数比较,择优录取。 按志愿顺序录取。

woniupengpeng的专栏 999

AD服务器搭建

一、角色安装1)打开服务器管理器,添加 角色和功能;2) 点 下一步;3)点 下一步;4)点 下一步;5)点击安装;6-1)将此服务器提升为域控制器;6-2)点下一步;6)输入密码 点 下一步;7)自动生成LIXF,点击下一步;8)确认目录,点下一步;8)确认安装条件,点安装; 8)安装成功,点关闭;...

潇峰的博客 6445

POJ-1057 FILE MAPPING 恶心模拟

题意:介绍一种控制台下的文件目录输出格式,要求进行模拟.详见代码 代码如下: #include &lt;cstdlib&gt; #include &lt;cstring&gt; #include &lt;cstdio&gt; #include &lt;iostream&gt; #include &lt;stack&gt; #include &lt;string&gt; #inc...

weixin_33912445的博客 149

KANO分析模型

KANO分析模型的基本概念,目的意义,应用场景,实现方法和示例等

JasonH2021的博客 3065

keil自动分配SDRAM空间设置使用

1.修改.sct文件。

qizhi321123的博客 1404

1075: 聚餐人数统计-python

1075: 聚餐人数统计-python 题目描述: 马克思手稿中有这样一道趣味数学题:男人、女人和小孩总计n个人,在一家饭店里吃饭,共花了cost先令,每个男人各花3先令,每个女人各花2先令,每个小孩各花1先令,请用穷举法编程计算男人、女人和小孩各有几个。 输入 输入两个正整数,表示人数n和花费cost。 输出 若问题有解,则输出所有解,每行输出三个数据,代表男人、女人和小孩的人数,用空格分隔;若问题无解,则输出“No answer"。 样例输入 Copy 30 50 样例输出 Copy 0 20 10 1

qq_44011202的博客 774

【Qwen2微调实战】LLaMA-Factory框架对Qwen2-7B模型的微调实践

在人工智能的浪潮中,大型语言模型(LLMs)正逐渐成为研究和应用的热点。它们在自然语言处理(NLP)的各个领域,如文本生成、翻译、问答等任务中展现出了卓越的能力。Qwen2-7B模型,作为该领域的佼佼者,不仅因其庞大的参数量和强大的表示能力受到关注,更因其在微调后能够更好地适应特定任务而备受关注。本文将详细介绍如何利用LLaMA-Factory这一高效的微调框架对Qwen2-7B进行微调,以期达到提升模型在特定任务上的表现。

寻道AI,探索AI无限可能! 2万+

ZZULIOJ1075: 聚餐人数统计

【代码】ZZULIOJ1075: 聚餐人数统计。

m0_62355369的博客 843

unity6000.0.3版本URP下ScriptableRendererFeature如何实现一张自定义贴图效果?

🏆本文收录于 《全栈 Bug 调优(实战版)》 专栏。专栏聚焦真实项目中的各类疑难 Bug,从成因剖析 → 排查路径 → 解决方案 → 预防优化全链路拆解,形成一套可复用、可沉淀的实战知识体系。无论你是初入职场的开发者,还是负责复杂项目的资深工程师,都可以在这里构建一套属于自己的「问题诊断与性能调优」方法论,助你稳步进阶、放大技术价值。

**My Coding Family** 584

【异常】Hermes Agent调用z.ai接口失败(余额不足)API call failed (attempt 1/3): RateLimitError [HTTP 429]

补充说明:同步尝试解析接口对应网页时,出现“网页解析失败,可能是不支持的网页类型,请检查网页或稍后重试”提示,该提示不影响核心报错排查,仅作为辅助信息。

奶爸的编程之路,也就一周冷个三天 1193

1075. PAT Judge

题目链接:http://pat.zju.edu.cn/contests/pat-a-practise/1075 /* * 最后一个测试点错误原因:对成绩初始化时,错误。。。见具体代码处解释 * * 需要解决的几个问题: * 1. student应包含哪些成员,什么类型 * 2. 如何实现排序 * 3. 输入的成绩如何映射到student上,显然Hash。 * 本次使用vec

Sunshine 1143

为什么一个“时间片”能折腾 Linux 十年?

时间片扩展不是抢占调度器的控制权,也不是提升优先级。在“非常短暂、非常确定”的用户态临界区内,避免线程被不必要地抢占。用户态自旋锁(user-space spinlock)无系统调用的极短临界区高并发、低延迟的数据结构操作RSEQ(Restartable Sequences)保护区间一旦线程在临界区被抢占,系统整体性能反而下降。线程 A 拿着一个用户态锁线程 B 被调度上来,开始自旋等这个锁但 A 因为时间片用完,被调度器切走CPU 白白空转,所有线程都在浪费时间。

网络技术联盟站 253

ZZULIOJ1075~1082(每组数据占一行&&英文大小写)(C语言)

1075: 聚餐人数统计 注意!!!英文大小写!!! #include<stdio.h> #include<math.h> int main(){ int n,cost; scanf("%d %d",&n,&cost); int flag = 0; for(int i=0;i<=n;i++){ for(int j=0;j<=n;j+...

zzzbeauty的博客 2464

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

【ZZULIOJ】1075: 聚餐人数统计(Java)

马克思手稿中有这样一道趣味数学题:男人、女人和小孩总计n个人,在一家饭店里吃饭,共花了cost先令,每个男人各花3先令,每个女人各花2先令,每个小孩各花1先令,请用穷举法编程计算男人、女人和小孩各有几个。若问题有解,则输出所有解,每行输出三个数据,代表男人、女人和小孩的人数,用空格分隔;若问题无解,则输出“No answer"。输入两个正整数,表示人数n和花费cost。

L-China的博客 694

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

1075

#include #include main() { int n,sum=0,i; scanf("%d",&n); int a[n]; for(i=0;i<n;i++) { scanf("%d",&a[i]); } for(i=0;i<n;i++) { if(a[i]%2==0) { sum=sum+a[i]; } } printf("%d",sum);

张松超的博客 715

poj完整分类

DP:  1011   NTA                 简单题  1013   Great Equipment     简单题  1024   Calendar Game       简单题  1027   Human Gene Functions   简单题  1037   Gridland            简单题  1052   Algernon s Noxious

zhongkeli的专栏 7874

POJ 刷题顺序

POJ从简到难(按照AC数目排序)的列表

马必辰的博客 1万+

poj 几道简单的dp题

题目:poj 1836 题意: 求使数列程先递增后递减的形式需要去掉的数字个数。当然也可以直接递减或者只递减不递增。 分析: 用最长递增子序列的方法求,然后枚举两个起点的位置即可。 #include<cstdio> #include<cstring> #include<algorithm> using namespac...

290

郑州轻工业大学OJ合集(C语言)

郑州轻工业大学OJ平台题目参考代码

心之所向 9万+

zoj 1023 University Entrace Examination(婚姻匹配问题)

University Entrace Examination Time Limit: 2 Seconds      Memory Limit: 65536 KB There is a fierce competition among high-school graduates in Iran to pass the centralized nationwide university e

a709743744的博客 905

zzuli OJ 1075: 聚餐人数统计

Description 马克思手稿中有这样一道趣味数学题:男人、女人和小孩总计n个人,在一家饭店里吃饭,共花了cost先令,每个男人各花3先令,每个女人各花2先令,每个小孩各花1先令,请用穷举法编程计算男人、女人和小孩各有几个。 Input 输入两个正整数,表示人数n和花费cost。 Output 若问题有解,则输出所有解,每行输出三个数据,代表男人、女人和小孩的人数

强强强子的博客 8914

ZOJ 1023 University Entrace Examination(稳定匹配变形)

点击打开链接 这道题和最标准的稳定匹配不同的,就是男和女不是一个配一个,学生可能一个学校都不能去,但一个学校却有可能录取多个学生。原来的模板,只需要改动woman数组,就是这个程序中的Woman数组。为了方便,把学生看成男,把学校看成女,那么Woman数组中对于每一个女性,都要保存目前所选的学生,不断更新。这道题只要满足稳定性,不会出现私奔的情况就可以了。

Muya 745
上一篇: 模板-Gale_Shapley稳定婚姻算法
下一篇: 2019-02-26-过山车-HDU2063-二分图匹配-匈牙利算法
silzero
博客等级 码龄8年 3粉丝 12原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值