1080. Graduate Admission (30)

时间限制
200 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

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)的更多相关文章

  1. pat 甲级 1080. Graduate Admission (30)

    1080. Graduate Admission (30) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue It ...

  2. PAT 甲级 1080 Graduate Admission (30 分) (简单,结构体排序模拟)

    1080 Graduate Admission (30 分)   It is said that in 2011, there are about 100 graduate schools ready ...

  3. PAT-1080 Graduate Admission (结构体排序)

    1080. Graduate Admission It is said that in 2013, there were about 100 graduate schools ready to pro ...

  4. 1080. Graduate Admission (30)

    时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue It is said that in 2013, there w ...

  5. PAT 1080. Graduate Admission (30)

    It is said that in 2013, there were about 100 graduate schools ready to proceed over 40,000 applicat ...

  6. 1080 Graduate Admission (30)(30 分)

    It is said that in 2013, there were about 100 graduate schools ready to proceed over 40,000 applicat ...

  7. PAT (Advanced Level) 1080. Graduate Admission (30)

    简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...

  8. 1080. Graduate Admission (30)-排序

    先对学生们进行排序,并且求出对应排名. 对于每一个学生,按照志愿的顺序: 1.如果学校名额没满,那么便被该学校录取,并且另vis[s][app[i].ranks]=1,表示学校s录取了该排名位置的学生 ...

  9. 【PAT甲级】1080 Graduate Admission (30 分)

    题意: 输入三个正整数N,M,K(N<=40000,M<=100,K<=5)分别表示学生人数,可供报考学校总数,学生可填志愿总数.接着输入一行M个正整数表示从0到M-1每所学校招生人 ...

随机推荐

  1. 点石成金:访客至上的网页设计秘笈(原书第2版) 中文PDF版

    可用性设计是Web设计中最重要也是难度最大的一项任务.本书作者根据多年从业的经验,剖析用户的心理,在用户使用的模式.为扫描进行设计.导航设计.主页布局.可用性测试等方面提出了许多独特的观点,并给出了大 ...

  2. POJO 与 JavaBean 的区别 !

    $说明: POJO :全称(Plain Old Java Object)翻译为“普通旧Java对象” 通俗理解为“一个简单的java对象”. JavaBean: 是一种JAVA语言写成的可重用组件,是 ...

  3. Binder学习笔记(二)——defaultServiceManager()返回了什么?

    不管是客户端还是服务端,头部都要先调用 sp < IServiceManager > sm = defaultServiceManager(); defaultServiceManager ...

  4. day03-Linux操作系统目录结构

    一. Linux系统目录表示        ‘/’表示根目录:                                                            ‘.’表示当前目录 ...

  5. Kafka学习文档

    本教程假定您是一只小白,没有Kafka 或ZooKeeper 方面的经验. Kafka脚本在Unix和Windows平台有所不同,在Windows平台,请使用 bin\windows\ 而不是bin/ ...

  6. AngularJS(四)——ng-controller(控制器)

    前言 上篇大概说了一下指令的应用格式以及创建自定义指令方法,本篇重点介绍一些ng-controller都有哪些小作用. 内容 通过修改控制器部分,修改显示界面. Demo <div ng-app ...

  7. 9、OpenCV Python 边缘保留滤波

    __author__ = "WSX" import cv2 as cv import numpy as np # 边缘保留滤波 十分重要(美颜的核心) # 高斯双边模糊(考虑到了像 ...

  8. P2542 [AHOI2005]航线规划 LCT维护双连通分量

    \(\color{#0066ff}{ 题目描述 }\) 对Samuel星球的探险已经取得了非常巨大的成就,于是科学家们将目光投向了Samuel星球所在的星系--一个巨大的由千百万星球构成的Samuel ...

  9. CF912E Prime Gift 数学

    Opposite to Grisha's nice behavior, Oleg, though he has an entire year at his disposal, didn't manag ...

  10. PAT天梯赛 L1-050 倒数第N个字符串

    题目链接:点击打开链接 给定一个完全由小写英文字母组成的字符串等差递增序列,该序列中的每个字符串的长度固定为 L,从 L 个 a 开始,以 1 为步长递增.例如当 L 为 3 时,序列为 { aaa, ...