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每所学校招生人 ...
随机推荐
- mvvm模式下在WPF项目中动态加载项目的程序集和类
在mvvm模式的wpf项目中有个需求需要去加载解决方案的程序集,并且根据程序集去动态加载当前程序集的类,做成下拉框形式. 效果: //全局定义 private ComboBox abList= nul ...
- P2542 [AHOI2005]航线规划 LCT维护双连通分量
\(\color{#0066ff}{ 题目描述 }\) 对Samuel星球的探险已经取得了非常巨大的成就,于是科学家们将目光投向了Samuel星球所在的星系--一个巨大的由千百万星球构成的Samuel ...
- P3272 [SCOI2011]地板
\(\color{#0066ff}{ 题目描述 }\) lxhgww的小名叫"小L",这是因为他总是很喜欢L型的东西.小L家的客厅是一个R*C的矩形,现在他想用L型的地板来铺满整个 ...
- socket套接字基本概念
int socket()函数创建的是套接字socket,返回的是socket描述符(套接字描述符),其实就是文件描述符,socket(套接字)其实就是文件 socket()创建了套接字(文件),只是开 ...
- kuangbin专题十六 KMP&&扩展KMP HDU1238 Substrings
You are given a number of case-sensitive strings of alphabetic characters, find the largest string X ...
- CuteFTP文件列表按名称排序,有中文文件名时,软件死掉的解决办法
看到很多人的解决办法是切换到一个没有中文的文件夹,点击排序后,再切换回来,这个的确是可以解决问题,但是有些繁琐! 直接一步到位的解决办法是: 依次点击菜单:工具->全局选项->导航-> ...
- Solr学习笔记(2) —— Solr管理索引库
一.维护索引 1.1 添加/更新文档 1.2 批量导入数据(使用dataimport) 第一步:把mysql的数据驱动.以及dataimport插件依赖的jar包添加到solrcore(collect ...
- Flask&&人工智能AI -- 8 HTML5+ 初识,HBuilder,夜神模拟器,Webview
昨日内容回顾 1.增删改查: 增: db.collections.insert({a:1}) // 官方不推荐了 db.collections.insertMany([{a:1},{b:1}]) in ...
- macOS(OS X)安装与配置 Homebrew
Homebrew 是 macOS 平台的软件包管理器,相当于 Linux 常用的 apt-get,zypper,pacman 等. 安装: 打开终端,逐条执行以下命令 首先需要安装依赖包 Xcode, ...
- VScode中Go的相关插件的安装
一.安装Go插件失败 使用VScode时,当我们安装完go语言扩展时,新建一个go的源码文件,进行保存时,会提示我们需要安装一些go的扩展插件,可别小看这些插件,这些插件都是非常有用的,比如说自动补全 ...