1080 Graduate Admission (30分) 簡單模擬+STL(erase操作超時)
阿新 • • 發佈:2020-08-27
題目
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; }