pat1080. Graduate Admission (30)
1080. Graduate Admission (30)
It is said that in 2013, there were about 100 graduate schools ready to proceed over 40,000 applications in Zhejiang Province. It would help a lot if you could write a program to automate the admission procedure.
Each applicant will have to provide two grades: the national entrance exam grade GE, and the interview grade GI. The final grade of an applicant is (GE + GI) / 2. The admission rules are:
- The applicants are ranked according to their final grades, and will be admitted one by one from the top of the rank list.
- If there is a tied final grade, the applicants will be ranked according to their national entrance exam grade GE. If still tied, their ranks must be the same.
- Each applicant may have K choices and the admission will be done according to his/her choices: if according to the rank list, it is one's turn to be admitted; and if the quota of one's most preferred shcool is not exceeded, then one will be admitted to this school, or one's other choices will be considered one by one in order. If one gets rejected by all of preferred schools, then this unfortunate applicant will be rejected.
- If there is a tied rank, and if the corresponding applicants are applying to the same school, then that school must admit all the applicants with the same rank, even if its quota will be exceeded.
Input Specification:
Each input file contains one test case. Each case starts with a line containing three positive integers: N (<=40,000), the total number of applicants; M (<=100), the total number of graduate schools; and K (<=5), the number of choices an applicant may have.
In the next line, separated by a space, there are M positive integers. The i-th integer is the quota of the i-th graduate school respectively.
Then N lines follow, each contains 2+K integers separated by a space. The first 2 integers are the applicant's GE and GI, respectively. The next K integers represent the preferred schools. For the sake of simplicity, we assume that the schools are numbered from 0 to M-1, and the applicants are numbered from 0 to N-1.
Output Specification:
For each test case you should output the admission results for all the graduate schools. The results of each school must occupy a line, which contains the applicants' numbers that school admits. The numbers must be in increasing order and be separated by a space. There must be no extra space at the end of each line. If no applicant is admitted by a school, you must output an empty line correspondingly.
Sample Input:
11 6 3
2 1 2 2 2 3
100 100 0 1 2
60 60 2 3 5
100 90 0 3 4
90 100 1 2 0
90 90 5 1 3
80 90 1 0 2
80 80 0 1 2
80 80 0 1 2
80 70 1 3 2
70 80 1 2 3
100 100 0 2 4
Sample Output:
0 10
3
5 6 7
2 8 1 4
方法一:
代码改得很久,有些生疏。
#include<cstdio>
#include<cstring>
#include<iostream>
#include<stack>
#include<set>
#include<map>
#include<queue>
#include<algorithm>
using namespace std;
struct application{
int GE,GI,sum,num;
int want[];//开始写成3,错了!
};
vector<int> sch[];
application app[];
int sum[],GE[];
int school[];
bool cmp(application a,application b){
if(a.sum==b.sum){
return a.GE>b.GE;
}
return a.sum>b.sum;
}
int main(){
//freopen("D:\\INPUT.txt","r",stdin);
int n,m,k,i,j;
scanf("%d %d %d",&n,&m,&k);
for(i=;i<m;i++){
scanf("%d",&school[i]);
}
for(i=;i<n;i++){
scanf("%d %d",&app[i].GE,&app[i].GI);
GE[i]=app[i].GE;
sum[i]=app[i].sum=app[i].GE+app[i].GI;
app[i].num=i;
for(j=;j<k;j++){//开始写成3,错了!
scanf("%d",&app[i].want[j]);
}
}
sort(app,app+n,cmp); /*for(i=0;i<n;i++){
cout<<app[i].GE<<" "<<app[i].GI<<" "<<app[i].sum<<endl;
}*/ int schnum;
for(i=;i<n;i++){
for(j=;j<k;j++){
schnum=app[i].want[j];
if(sch[schnum].size()<school[schnum]||(sum[sch[schnum].back()]==app[i].sum&&GE[sch[schnum].back()]==app[i].GE)){//这里要注意排序后,编号都乱了,编号不再和当前的元素对应
sch[schnum].push_back(app[i].num);
break;
}
}
}
vector<int>::iterator it;
for(i=;i<m;i++){
if(sch[i].size()){
sort(sch[i].begin(),sch[i].end());
it=sch[i].begin();
printf("%d",*it);
it++;
for(;it!=sch[i].end();it++){
printf(" %d",*it);
}
}
printf("\n");
}
return ;
}
方法二:
#include<cstdio>
#include<cstring>
#include<iostream>
#include<stack>
#include<set>
#include<map>
#include<queue>
#include<algorithm>
using namespace std;
struct application{
int GE,GI,sum,num;
int want[];
};
vector<int> sch[];
application app[];
int school[];
bool cmp(application a,application b){
if(a.sum==b.sum){
return a.GE>b.GE;
}
return a.sum>b.sum;
}
bool vis[];//判断是否之前已经满了
int main(){
//freopen("D:\\INPUT.txt","r",stdin);
int n,m,k,i,j;
scanf("%d %d %d",&n,&m,&k);
for(i=;i<m;i++){
scanf("%d",&school[i]);
}
for(i=;i<n;i++){
scanf("%d %d",&app[i].GE,&app[i].GI);
app[i].sum=app[i].GE+app[i].GI;
app[i].num=i;
for(j=;j<k;j++){
scanf("%d",&app[i].want[j]);
}
}
sort(app,app+n,cmp); /*for(i=0;i<n;i++){
cout<<app[i].GE<<" "<<app[i].GI<<" "<<app[i].sum<<endl;
}*/
int count;
for(i=;i<n;){
queue<int> q;
count=;
for(j=i;j<n;j++){
if(app[j].sum==app[i].sum&&app[j].GE==app[i].GE){
q.push(j);
count++;
}
else{
break;
}
}
i=j;
int cur;
int schnum;
int temp;
for(j=;j<k;j++){
memset(vis,false,sizeof(vis));
temp=count;
while(temp--){
cur=q.front();
q.pop();
schnum=app[cur].want[j];
if(school[schnum]>||vis[schnum]){//是因为同等级的人“虚”满,还有名额
vis[schnum]=true;
school[schnum]--;
sch[schnum].push_back(app[cur].num);
count--;
}
else{
q.push(cur);
}
}
}
}
for(i=;i<m;i++){
if(sch[i].size()){
sort(sch[i].begin(),sch[i].end());
printf("%d",sch[i][]);
}
for(j=;j<sch[i].size();j++){
printf(" %d",sch[i][j]);
}
printf("\n");
}
return ;
}
pat1080. Graduate Admission (30)的更多相关文章
- pat 甲级 1080. Graduate Admission (30)
1080. Graduate Admission (30) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue It ...
- PAT 甲级 1080 Graduate Admission (30 分) (简单,结构体排序模拟)
1080 Graduate Admission (30 分) It is said that in 2011, there are about 100 graduate schools ready ...
- PAT-1080 Graduate Admission (结构体排序)
1080. Graduate Admission It is said that in 2013, there were about 100 graduate schools ready to pro ...
- 1080. Graduate Admission (30)
时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue It is said that in 2013, there w ...
- PAT 1080. Graduate Admission (30)
It is said that in 2013, there were about 100 graduate schools ready to proceed over 40,000 applicat ...
- 1080 Graduate Admission (30)(30 分)
It is said that in 2013, there were about 100 graduate schools ready to proceed over 40,000 applicat ...
- PAT (Advanced Level) 1080. Graduate Admission (30)
简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...
- 1080. Graduate Admission (30)-排序
先对学生们进行排序,并且求出对应排名. 对于每一个学生,按照志愿的顺序: 1.如果学校名额没满,那么便被该学校录取,并且另vis[s][app[i].ranks]=1,表示学校s录取了该排名位置的学生 ...
- 【PAT甲级】1080 Graduate Admission (30 分)
题意: 输入三个正整数N,M,K(N<=40000,M<=100,K<=5)分别表示学生人数,可供报考学校总数,学生可填志愿总数.接着输入一行M个正整数表示从0到M-1每所学校招生人 ...
随机推荐
- 国外物联网平台(3):IBM Watson IoT
国外物联网平台(3)——IBM Watson IoT 马智 平台定位 提供全面管理的云托管服务,旨在简化并从 IoT 设备中获得价值. Watson IoT Platform 提供对 IoT 设备和数 ...
- SharpCompress压缩和解压缩,并解决压缩的中文乱码问题
一.下载SharpCompress库 二.解压缩 (1)不带密码 /// <summary> /// 解压缩(支持rar,zip) /// </summary> /// < ...
- PCANet: A Simple Deep Learning Baseline for Image Classification?--名词解释
1 上采样与下采样 缩小图像(或称为下采样(subsampled)或降采样(downsampled))的主要目的有两个: 使得图像符合显示区域的大小 生成对应图像的缩略图 下采样原理:对于一幅图像I尺 ...
- tableView 的协议方法
需遵守协议 UITableViewDataSource, UITableViewDelegate,并设置代理 UITableViewDelegate 继承自 UIScrollViewDelegate ...
- day05.1-文件归档与压缩
>:覆盖式修改文件内容.如: a). cat /etc/passwd > new_pass.txt(将/etc/passwd中的内容覆盖式复制到new_pass.txt中,若n ...
- win10更新后IE不见了
只是快捷方式不见了,到C:\Program Files\internet explorer\iexplore.exe就看到了,可以正常运行
- 【以太坊开发】区块链中的预言机:Oraclize原理介绍
智能合约的作用很多,但是很多数据还是要基于互联网,那么如何在合约中获取互联网中的数据?Oraclize就是为了这个目的而诞生的. 工作原理: 智能合约通过对Oraclize发布一个合约之间的调用请求来 ...
- 阿里云服务器部署Tornado应用指南
本篇详细介绍tornado应用部署到阿里云服务器上的全过程. Tornado程序地址:github https://github.com/ddong8/ihasy.git 准备工作:阿里云服务器Cen ...
- MySql8最新配置方式(完美)
下载MYSQL8 地址:https://www.mysql.com/downloads/ 1.滑动网页到最下面,选择Community (GPL) Downloads » 2.选择MySQL Comm ...
- Gym - 101615 D Rainbow Roads dfs序
题目传送门 题目大意: 给出一颗树,每条边都有一个颜色,对一个点来说,如果其他所有点到这个点的简单路径,相连的边颜色都不同,这个点即合法点,统计所有的合法点. 思路: 对于一个节点来说 1.如果这个节 ...