1080 Graduate Admission (30分) 简单模拟+STL(erase操作超时)

题目

https://pintia.cn/problem-sets/994805342720868352/problems/994805387268571136

题意

模拟高校投档流程

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

这题有一个点容易超时
原因是对vector使用了erase操作~

code

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int N,M,K;
struct student{
    int id;
    int GE,GI;
    int x[6];
}temp;
vector<student>st;
int sc[101];
vector<int>ans[101];
bool cmp(student a,student b)
{
    if(a.GE+a.GI!=b.GE+b.GI) return a.GE+a.GI>b.GE+b.GI;
    else return a.GE>b.GE;
}
int main()
{
    scanf("%d%d%d",&N,&M,&K);
    for(int i=0;i<M;++i) scanf("%d",sc+i);
    for(int i=0;i<N;++i)
    {
        scanf("%d%d",&temp.GE,&temp.GI);
        for(int j=0;j<K;++j) scanf("%d",&temp.x[j]);
        temp.id=i;
        st.push_back(temp);
    }
    sort(st.begin(),st.end(),cmp);
    int p=0;
    while(p<N)
    {
        for(int i=0;i<K;++i)
        {
            int y=st[p].x[i];//选学校y
            if(sc[y]>0)//y有名额
            {
                ans[y].push_back(st[p].id);
                sc[y]--;
                int GE1=st[p].GE,GI1=st[p].GI;
                ++p;
                while(p<N)//排名相同也得进
                {
                    if(GE1==st[p].GE && GI1==st[p].GI) {
                        ans[y].push_back(st[p].id);
                        sc[y]--;
                        ++p;
                    }
                    else break;
                }
                break;
            }
            else if(i==K-1){//落选
                ++p;
            }
        }
    }
    for(int i=0;i<M;++i)
    {
        sort(ans[i].begin(),ans[i].end());
        for(int j=0;j<ans[i].size();++j)
        {
            printf("%d",ans[i][j]);
            if(j!=ans[i].size()-1) printf(" ");
        }
        printf("\n");
    }
    return 0;
}
posted @ 2020-08-27 13:37  liuyongliu  阅读(112)  评论(0编辑  收藏  举报