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每所学校招生人 ...
随机推荐
- 微信开放平台 redirect_uri参数错误
微信开放平台 redirect_uri参数错误 请注意是开放平台开放平台,公众平台和开放平台不是同一个. 解决办法 在写 授权回调域 时,地址只用写到域名级,不能写到域名下一级,这和QQ互联的回调 ...
- metasploit 读书笔记-信息收集
三、信息收集 被动信息收集 在不接触目标系统时进行的信息收集,包括使用工具Yeti、Whois (1)Whois msf > whois secmaniac.net (2)Netcraft:fi ...
- 502. IPO
Suppose LeetCode will start its IPO soon. In order to sell a good price of its shares to Venture Cap ...
- [hdu 1568] Fibonacci数列前4位
2007年到来了.经过2006年一年的修炼,数学神童zouyu终于把0到100000000的Fibonacci数列(f[0]=0,f[1]=1;f[i] = f[i-1]+f[i-2](i>=2 ...
- 斐波那契数列的Python实现
斐波那契数列的Python实现:递归实现.非递归实现.斐波那契数列生成器: \[ \begin{equation} F(n)= \begin{cases} n & n=0, 1\\ F(n ...
- 博弈论-一堆nim博弈合在一起
今天A了张子苏大神的的题,感觉神清气爽. 一篇对于多层nim博弈讲的很透彻的博文:http://acm.hdu.edu.cn/forum/read.php?fid=9&tid=10617 我来 ...
- HTTP协议和WebSocket协议(一)
转自:https://www.jianshu.com/p/0e5b946880b4# HTTP HTTP的地址格式如下: http_URL = "http:" "//&q ...
- Linux中切换前后台命令:ctrl+z,bg,fg,jobs
一.运行某些服务的时候,我希望切换到后台运行: 两种方法: 1.可以在运行的时候,在启动服务命令的最后面加一个字符&,例如 ./serviceStart & 2.在服务启动后,按ctr ...
- vscode 注册表
Windows Registry Editor Version 5.00 ; Open files [HKEY_CLASSES_ROOT\*\shell\Open with VS Code] @=&q ...
- vim 常用配置项
#设置行号set nu #设置下划线 set cursorline #设置自动锁紧 set autoindent #设置shift空格 set shiftwidth=4 #设置c 风格缩进 set c ...