University Entrace Examination zoj1023
学校招收学生 优先级按照: 分数 是否本地 志愿先后
相当于 女的开后宫
对gs进行略微修改
结束的条件为每个男的表白完所有女的
第二部分比较时 找出女的后宫里的吸引力最弱的男的比较 然后是否取代
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define N 200
#define eps 1e-6
using namespace std;
struct node
{
int id,region,score,k;
}stu[N];
struct node1
{
int region,num;
}sch[N];
struct node2
{
int cnt;
int manname[N];
}woman[N];
int r,n,m;
int map1[N][N],map2[N][N],man[N],times[N],vis[N];
int cmp(node a,node b)
{
if(a.region==r)
{
if(b.region==r)
return a.score>b.score;
if(b.region!=r)
{
if(abs(a.score-0.7*b.score)<eps)
return ;
else
return a.score>0.7*b.score;
}
}
else if(b.region==r)
{
if(a.region==r)
return a.score>b.score;
if(a.region!=r)
{
if(abs(b.score-0.7*a.score)<eps)
return ;
else
return b.score<0.7*a.score;
}
}
else
return a.score>b.score;
}
int cmp1(node a,node b)
{
return a.id<b.id;
}
void makerank()
{
int i,j;
for(i=;i<=m;i++)
{
r=sch[i].region;
sort(stu+,stu+n+,cmp);
for(j=;j<=n;j++)
map2[i][stu[j].id]=j;
}
sort(stu+,stu+n+,cmp1);
}
void Gale_Shapley()
{
int flag=,i,j,worstrank,worstrankj;
memset(man,,sizeof(man));
for(i=;i<=n;i++)
times[i]=;
for(i=;i<=n;i++)
vis[i]=;
for(i=;i<=m;i++)
woman[i].cnt=;
while(flag)
{
flag=;
for(i=;i<=n;i++)
{
while(!man[i]&&!vis[i])
{
flag=;
if(times[i]>stu[i].k)
{
vis[i]=;
break;
}
int name=map1[i][times[i]];
if(woman[name].cnt<sch[name].num)
{
woman[name].manname[++woman[name].cnt]=i;
man[i]=name;
times[i]++;
}
else if(woman[name].cnt==sch[name].num)
{
worstrank=;
for(j=;j<=woman[name].cnt;j++)
{
if(map2[name][woman[name].manname[j]]>worstrank)
{
worstrank=map2[name][woman[name].manname[j]];
worstrankj=j;
}
}
if(map2[name][i]<worstrank)
{
man[woman[name].manname[worstrankj]]=;
woman[name].manname[worstrankj]=i;
man[i]=name;
times[i]++;
}
else
times[i]++;
}
}
}
}
}
int main()
{
int T,j,i;
scanf("%d",&T);
while(T--)
{
memset(map1,,sizeof(map1));
memset(map2,,sizeof(map2));
scanf("%d%d",&n,&m);
for(i=;i<=n;i++)
{
stu[i].id=i;
scanf("%d%d%d",&stu[i].region,&stu[i].score,&stu[i].k);
for(j=;j<=stu[i].k;j++)
{
scanf("%d",&map1[i][j]);
}
}
for(i=;i<=m;i++)
{
scanf("%d%d",&sch[i].region,&sch[i].num);
}
makerank();
Gale_Shapley();
for(i=;i<=n;i++)
if(vis[i])
printf("not accepted\n");
else
printf("%d\n",man[i]);
if(T) printf("\n");
}
return ;
}
University Entrace Examination zoj1023的更多相关文章
- POJ题目细究
acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP: 1011 NTA 简单题 1013 Great Equipment 简单题 102 ...
- 【转】POJ百道水题列表
以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...
- POJ题目排序的Java程序
POJ 排序的思想就是根据选取范围的题目的totalSubmittedNumber和totalAcceptedNumber计算一个avgAcceptRate. 每一道题都有一个value,value ...
- HDU 4442 Physical Examination
Physical Examination Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64 ...
- HDU 4442 Physical Examination(贪心)
HDU 4442 Physical Examination(贪心) 题目链接http://acm.split.hdu.edu.cn/showproblem.php?pid=4442 Descripti ...
- hdu 4442 Physical Examination 贪心排序
Physical Examination Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- CSUOJ 1603 Scheduling the final examination
1603: Scheduling the final examination Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 49 Solved: 1 ...
- 2017 New Year’s Greetings from Sun Yat-sen University
As winter turns to spring, the world around us begins to take on an air of freshness. As 2017 is fa ...
- Divide and conquer:Moo University - Financial Aid(POJ 2010)
Moo University - Financial Aid 其实是老题了http://www.cnblogs.com/Philip-Tell-Truth/p/4926008.html 这一次我们换二 ...
随机推荐
- Python之旅:MySQL系列
第一篇:初识数据库 第二篇:库操作 第三篇:表操作 第四篇:数据操作 第五篇:索引原理与慢查询优化 第六篇:数据备份.pymysql模块 第七篇:视图.触发器.事务.存储过程.函数 第八篇:ORM框架 ...
- JSON.parseObject(String str)与JSONObject.parseObject(String str)的区别
一.首先来说说fastjson fastjson 是一个性能很好的 Java 语言实现的 JSON 解析器和生成器,来自阿里巴巴的工程师开发.其主要特点是: ① 快速:fastjson采用独创的算法, ...
- Codeforces 662 C. Binary Table
http://codeforces.com/contest/662/problem/C 题意:n行m列01矩阵,每次可以反转一行或一列,问最后最少可以剩下多少个1 n只有20,把行状态压缩 操作奇数次 ...
- bzoj千题计划236:bzoj2300: [HAOI2011]防线修建
http://www.lydsy.com/JudgeOnline/problem.php?id=2300 维护动态凸包,人懒用的set 用叉积判断,不要用斜率 #include<set> ...
- starUML的使用方法和各种线条的含义
使用方法https://www.cnblogs.com/syncCN/p/5433746.html 各种线条的含义:https://www.cnblogs.com/huaxingtianxia/p/6 ...
- Spring Mvc + Maven + BlazeDS 与 Flex 通讯 (七)
BlazeDS 说明 BlazeDS是由Adobe开源的基于amf协议的,用于解决flex与java通讯的组件; 基于传统的文本协议的XML传输方式,在抽象层方面会有很大的压力,特别在需要序列化与反序 ...
- BZOJ2428 均分数据
2428: [HAOI2006]均分数据 Time Limit: 5 Sec Memory Limit: 128 MB Description 已知N个正整数:A1.A2.…….An .今要将它们分 ...
- 20155210潘滢昊 2016-2017-2 《Java程序设计》第6周学习总结
20155210 2016-2017-2 <Java程序设计>第6周学习总结 教材学习内容总结 流(Stream)是对「输入输出」的抽象,注意「输入输出」是相对程序而言的 InputStr ...
- iOS代码规范之命名规范
技术博客http://www.cnblogs.com/ChenYilong/ 新浪微博http://weibo.com/luohanchenyilong 命名规范类命名 首字母大写,之 ...
- Android View坐标系详解(getTop()、getX、getTranslationX...)
View 提供了如下 5 种方法获取 View 的坐标:1. View.getTop().View.getLeft().View.getBottom().View.getRight();2. View ...