B1080 Graduate Admission (填志愿录取模拟)

B1080 Graduate Admission (30分)

  • If there is a tied final grade, the applicants will be ranked according to their national entrance exam grade G​E

  • If still tied, their ranks must be the same.
    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.

该题录取需要记录Rank,卡了一晚上的测试点1两分过不去,因为我自己在想到录取按最后一个人是否到达分数线,而忽略了题中指的是达到Rank,因为G和GE相等,Rank相等,但是总分不一定相等。

另外要注意的地方

  • GI和GE相加*2不会超int,题中没讲是否是整型,最好不要去除2比较G,避免了化整需要讨论的四舍五入
  • vector<int>a[MAX]的sort排序:
    1.sort(a[i].begin(),a[i].end())
    2.重写一个结构体,结构体里加vector<int>b
    sort(a[i].b.begin(),a[i].b.end());

对vector<int>a[MAX]的排序下次不要去搞什么sort(a[i],a[i]+m,cmp)了!!!

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string.h>
#include <cmath>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <stack>
#define lowbit(i)((i)&(-i))
using namespace std;
typedef long long ll;
const int MAX=40005;
const int INF=0x3f3f3f3f;
const int MOD=1000000007;
const int SQR=633;
int n,m,k;
int school[101];
map<int,int>minscore;
map<int,int>local;
struct node
{
    int GE,GI,G;
    int Rank;
    int id;
    int d[6];
}stu[MAX];
vector<int>sch[101];
bool cmp(node a,node b)
{
    if(a.G!=b.G)
        return a.G>b.G;
    else
        return a.GE>b.GE;
}
int main()
{
    scanf("%d%d%d",&n,&m,&k);
    for(int i=0;i<m;i++)
        scanf("%d",&school[i]);
    for(int i=0;i<n;i++)
    {
        stu[i].id=i;
        scanf("%d%d",&stu[i].GE,&stu[i].GI);
        stu[i].G=stu[i].GE+stu[i].GI;
        for(int j=0;j<k;j++)
            scanf("%d",&stu[i].d[j]);
    }
    sort(stu,stu+n,cmp);
    stu[0].Rank=1;
    for(int i=1;i<n;i++)
    {
        if(stu[i].G==stu[i-1].G&&stu[i].GE==stu[i-1].GE)
            stu[i].Rank=stu[i-1].Rank;
        else
            stu[i].Rank=i+1;
    }
    for(int i=0;i<n;i++)
    {
       for(int j=0;j<k;j++)
       {
        if(school[stu[i].d[j]]>=1)
        {
            sch[stu[i].d[j]].push_back(stu[i].id);
            school[stu[i].d[j]]--;
            minscore[stu[i].d[j]]=stu[i].Rank;
            local[stu[i].d[j]]=j;
            break;
        }
        else if(school[stu[i].d[j]]==0&&minscore[stu[i].d[j]]==stu[i].Rank&&local[stu[i].d[j]]==j)
        {
             sch[stu[i].d[j]].push_back(stu[i].id);
             break;
        }
       }
    }
    for(int i=0;i<m;i++)
    {
        sort(sch[i].begin(),sch[i].end());
        for(int j=0;j<sch[i].size();j++)
        {
            if(j==0)
                cout<<sch[i][j];
            else
                cout<<" "<<sch[i][j];
        }
        cout<<endl;
    }
    return 0;
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容