#define LOCAL
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
using namespace std;
struct mouse{
int w;
int r;
}mouse[1010];
int main()
{
#ifdef LOCAL
freopen("data.in","r",stdin);
freopen("data.out","w",stdout);
#endif // LOCAL
int n,m;
cin>>n>>m;
for(int i=0;i<n;i++){
cin>>mouse[i].w;
}
int id;
queue<int> q;
for(int i=0;i<n;i++){
cin>>id;
q.push(id);
}
int t=n,g;
while(q.size()!=1){
if(t%m==0)g=t/m;
else g=t/m+1;
for(int i=0;i<g;i++){
int k=q.front();
for(int j=0;j<m;j++){
if(i*m+j>=t)break;
int f=q.front();
if(mouse[k].w<mouse[f].w) k=f;
mouse[f].r=g+1;
q.pop();
}
q.push(k);
}
t=g;
}
mouse[q.front()].r=1;
for(int i=0;i<n;i++){
cout<<mouse[i].r;
if(i!=n-1)cout<<" ";
}
return 0;
}
【PAT】1056. Mice and Rice
最新推荐文章于 2019-11-23 15:38:37 发布