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. 温故而知新_C语言_递归

    递归. 是的,差不多就是这种感觉.上面就是类似递归的显示表现. 2017 10 24更新: 递归这个问题放了很久.也没有写.大概是自己还没有好好理解吧. 在这里写下自己理解的全部. 一 何为递归. 字 ...

  2. upper_bound下确界

    //uppper_bound上确界找出首个大于某值的元素 #include<algorithm> #include<iostream> using namespace std; ...

  3. Jmeter实现从csv文件中随机读取数据

    一.需求 参数放在csv文件中,文件格式如下,需求每次从文件中随机读取一行数据. 二.步骤 1.在csv文件中新增加一列,pl 2.新增一个配置原件-随机数,设置如下: 50是文件数据的行数 3.新增 ...

  4. Leetcode 121. Best Time to Buy and Sell Stock 最佳股票售卖时(动态规划,数组,模拟)

    题目描述 已知一个数组,第i个元素表示第i天股票的价格,你只能进行一次交易(买卖各一次),设计算法找出最大收益 测试样例 Input: [7, 1, 5, 3, 6, 4] Output: 5 最大收 ...

  5. python编程技巧

  6. poj 2763 求树上的两个节点的最短距离+在线修改答案

    题目链接: http://poj.org/problem?id=2763 #include<stdio.h> #include<string.h> #include<ma ...

  7. jQuery中animate()方法以及$('body').animate({"scrollTop":top})不被Firefox支持问题的解决

    $("body").animate({"scrollTop":top}): 只被chrome支持,而不被Firefox支持 $("html" ...

  8. 4.会话管理(Session)

    1.会话管理的概念和基本原理: 会话管理概念: 会话的实现过程: 2.使用Cookie.隐藏域.URL重写实现会话管理 创建并向客户端发送Cookie; 从客户端读取Cookies Cookie的方法 ...

  9. Python练习六十:网页分析,找出里面的正文与链接

    网页分析,找出里面的正文与链接 代码如下: from urllib import request from bs4 import BeautifulSoup request = request.url ...

  10. PHP artisan

    Artisan 是 Laravel 提供的 CLI(命令行接口),它提供了非常多实用的命令来帮助我们开发 Laravel 应用.前面我们已使用过 Artisan 命令来生成应用的 App Key 和控 ...