PAT 1080

排序题目,搞混了一件事情,那就是,排序结束之后顺序是变的啊亲... 很丑地解决了问题,其实应该对每一个学校维护一个last applicant比较,不过能过就行了

 1 #include <iostream>
 2 #include <vector>
 3 #include <algorithm>
 4
 5 using namespace std;
 6
 7 struct Applicant{
 8     int ge;
 9     int gi;
10     int score;
11
12     int idx;
13
14     vector<int> apply_school;
15 };
16
17 struct sort_op{
18     bool operator()(Applicant a1, Applicant a2){
19         if (a1.score != a2.score)
20             return (a1.score > a2.score);
21         return (a1.ge > a2.ge);
22     }
23 };
24
25 int main(){
26     int N, M, K;
27     cin >> N >> M >> K;
28
29     vector<Applicant> applicants(N);
30     vector<vector<int> > school_res(M);
31     vector<int> school_quato(M);
32
33     for (int i = 0; i < M; i++){
34         int cnt;
35         cin >> cnt;
36         school_quato[i] = cnt;
37     }
38
39     for (int i = 0; i < N; i++){
40         int ge, gi, idx;
41         cin >> ge >> gi;
42
43         applicants[i].ge = ge;
44         applicants[i].gi = gi;
45         applicants[i].score = ge + gi;
46         applicants[i].idx = i;
47
48         for (int j = 0; j < K; j++){
49             cin >> idx;
50             applicants[i].apply_school.push_back(idx);
51         }
52     }
53
54     vector<Applicant> bck_up = applicants;
55     sort(applicants.begin(), applicants.end(), sort_op());
56
57     for (int i = 0; i < N; i++){
58         for (int j = 0; j < K; j++){
59             int school_idx = applicants[i].apply_school[j];
60             if (school_quato[school_idx] > 0){
61                 school_quato[school_idx]--;
62                 school_res[school_idx].push_back(applicants[i].idx);
63
64                 break;
65             } else {
66                 if (school_res[school_idx].size() == 0) continue;
67                 int last = school_res[school_idx].back();
68                 if (applicants[i].gi == bck_up[last].gi && applicants[i].ge == bck_up[last].ge){
69                     school_res[school_idx].push_back(applicants[i].idx);
70                     school_quato[school_idx]--;
71                     break;
72                 }
73             }
74         }
75     }
76
77     for (int i = 0; i < school_res.size(); i++){
78         if (school_res[i].size() != 0){
79             sort(school_res[i].begin(), school_res[i].end());
80             cout << school_res[i][0];
81
82             for (int j = 1; j < school_res[i].size(); j++)
83                 cout << " " << school_res[i][j];
84         }
85
86         cout << endl;
87     }
88
89     return 0;
90 }
时间: 2024-10-07 05:28:25

PAT 1080的相关文章

PAT 1080. 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 ap

PAT 1080 MOOC期终成绩

https://pintia.cn/problem-sets/994805260223102976/problems/994805261493977088 对于在中国大学MOOC(http://www.icourse163.org/ )学习"数据结构"课程的学生,想要获得一张合格证书,必须首先获得不少于200分的在线编程作业分,然后总评获得不少于60分(满分100).总评成绩的计算公式为 0,如果 G?mid?term??>G?final??:否则总评 G 就是 G?final?

浙大PAT考试1077~1080(2014上机复试题目)

题目地址:点击打开链接 还是太弱. . 英文太差.,, 预计要等待被虐了.. 1077 找最长的公共后缀,暴力就能够写: #include<iostream> #include<cstdio> #include<cmath> #include<algorithm> #include<cstring> #include<string> using namespace std; char a[105][1005]; int milen;

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

简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<map> #include<stack> #include<queue> #include<string> #include<iostream> #include<algorithm> using namespace std;

PAT(A) 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 t

PAT:1080. Graduate Admission (30) AC

#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; struct Student { int GE,GI,sum,rank,ID; int prefer[6]; }STU[40066]; struct School { int want; //各学校招生人数 int get; //已招到的人数 int line; //最后一名进来的排名线 int queue[4006

PAT:1080. Graduate Admission (30) 全错

#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; struct Student { int GE,GI,sum,rank,ID; int prefer[6]; }STU[40066]; struct School { int want; //各学校招生人数 int get; //已招到的人数 int line; //最后一名进来的排名线 int queue[4006

PAT:1080. Graduate Admission (30) 部分错误(录取以学校为导向而不是考生志愿为导向导致的错误)

#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; int want[106]; //各学校招生人数 struct Student { int GE,GI,sum,rank,ID; int prefer[6]; bool R; //代表该生录取情况 }STU[40066]; bool cmp(Student a,Student b) { if(a.sum!=b.sum

PAT 1009 说反话 C语言

给定一句英语,要求你编写程序,将句中所有单词的顺序颠倒输出. 输入格式:测试输入包含一个测试用例,在一行内给出总长度不超过80的字符串.字符串由若干单词和若干空格组成,其中单词是由英文字母(大小写有区分)组成的字符串,单词之间用1个空格分开,输入保证句子末尾没有多余的空格. 输出格式:每个测试用例的输出占一行,输出倒序后的句子. 输入样例: Hello World Here I Come 输出样例: Come I Here World Hello 1 #include<stdio.h> 2 #