二次更新
正确答案
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
const int maxn = 1e5 + 10;
struct point {
int id, ge, gi, fg;
int choice[5];
bool operator<(const point &x)const
{
return fg == x.fg ? ge > x.ge: fg > x.fg;
}
}a[maxn];
vector<int>school[100];
int n, m, k, quota[100];
int main()
{
scanf("%d%d%d", &n, &m, &k);
for (int i = 0; i < m; i++)scanf("%d", "a[i]);
for (int i = 0; i < n; i++)
{
a[i].id = i;
scanf("%d%d", &a[i].ge, &a[i].gi);
a[i].fg = (a[i].ge + a[i].gi) / 2;
for (int j = 0; j < k; j++)scanf("%d", &a[i].choice[j]);
}
sort(a, a + n);
int pre = -1; //pre记录上一个录取的学校序号
for (int i = 0; i < n; i++)
{
for (int j = 0; j < k; j++)
{
if (quota[a[i].choice[j]])
{
school[a[i].choice[j]].push_back(a[i].id);
quota[a[i].choice[j]]--;
pre = j;
break;
}
else if (pre != -1 && a[i].fg == a[i - 1].fg&&a[i].ge == a[i - 1].ge)
{
school[a[i].choice[pre]].push_back(a[i].id);
break;
}
}
}
for (int i = 0; i < m; i++)
{
if (school[i].size() == 0)printf("\n");
else
{
sort(school[i].begin(), school[i].end());
for (int j = 0; j < school[i].size(); j++)
printf("%d%s", school[i][j], j == school[i].size() - 1 ? "\n" : " ");
}
}
return 0;
}
/*
5 5 3
0 0 0 5 5
100 100 0 1 2
100 99 1 2 0
99 100 2 1 0
99 99 1 0 2
98 98 2 0 1
*/
之前一个测试点总是段错误,后来发现maxn写小了,,,,改大就过了
下面答案有问题,测试数据里没有第一个学校不招人的情况,,,,
/*
5 5 3
0 0 0 5 5
100 100 0 1 2
100 99 1 2 0
99 100 2 1 0
99 99 1 0 2
98 98 2 0 1
*/
这组数据下面这个程序过不了的
但是测试点都能过,反正,,,这答案不算对
以下为原答案
真的很高兴!!第一次做出30分题目,行数还算不多
就是一个排序题
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
const int maxn = 4e5 + 10;
int n, m, k;
struct stu {
int id, ge, gi, fg;
vector<int>school;
bool operator<(const stu&a)const
{
return (ge + gi) / 2 == (a.ge + a.gi) / 2 ? ge > a.ge: (ge + gi) / 2 > (a.ge + a.gi) / 2;
}
};
vector<stu>p;
vector<int>ad[110];
int qu[110];
int main()
{
scanf("%d%d%d", &n, &m, &k);
for (int i = 0; i < m; i++)scanf("%d", &qu[i]);
for (int i = 0; i < n; i++)
{
stu x;
x.id = i;
scanf("%d%d", &x.ge, &x.gi);
x.fg = (x.ge + x.gi) / 2;
for(int i=0;i<k;i++)
{
int y;
scanf("%d", &y);
x.school.push_back(y);
}
p.push_back(x);
}
sort(p.begin(), p.end());
int t; //t用来记录前一个的排名,如果后一个和前一个排名相同,会用到它
for (int i = 0; i < p.size(); i++)
{
if (i == 0)ad[p[i].school[0]].push_back(p[i].id),t= p[i].school[0], qu[p[i].school[0]]--;
else
{
for (int j = 0; j < p[i].school.size(); j++)
{
if (qu[p[i].school[j]] > 0) {
ad[p[i].school[j]].push_back(p[i].id),t= p[i].school[j], qu[p[i].school[j]]--; break;
}
else if (p[i].fg == p[i - 1].fg&&p[i].ge == p[i-1].ge) {
ad[t].push_back(p[i].id); break; //此处用到t
}
}
}
}
for (int i = 0; i < m; i++)
{
sort(ad[i].begin(), ad[i].end());
if (ad[i].size() == 0)printf("\n");
else { for (int j = 0; j < ad[i].size(); j++)printf("%s%d", j == 0 ? "" : " ", ad[i][j]); printf("\n"); }
}
return 0;
}