#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;
struct mouse
{
int no,weight,rank;
bool operator < (const mouse& m) const
{
return weight < m.weight;
}
};
class CA
{
public:
void run();
int np,ng;
vector<mouse> v;
vector<int> ri;
vector<vector<mouse> > vv;
};
void CA::run()
{
scanf("%d%d",&np,&ng);
v.resize(np);
int i,j,k;
for(i=0;i<v.size();i++)
{
scanf("%d",&v[i].weight);
v[i].rank=1;
v[i].no=i;
}
ri.resize(np);
for(i=0;i<ri.size();i++)
{
scanf("%d",&ri[i]);
}
int gnum;
while(1)
{
gnum=(np-1)/ng+1;
vv.clear();
vv.resize(gnum);
for(i=0,j=0;i<ri.size();i++)
{
if(v[ri[i]].rank>1) continue;
if(vv[j].size()>=ng) j++;
vv[j].push_back(v[ri[i]]);
}
for(i=0;i<vv.size();i++)
{
int imax;
imax=max_element(vv[i].begin(),vv[i].end())-vv[i].begin();
for(j=0;j<vv[i].size();j++)
{
if(j==imax) continue;
v[vv[i][j].no].rank=vv.size()+1;
}
}
np=gnum;
if(np<=1) break;
}
for(i=0;i<v.size()-1;i++) printf("%d ",v[i].rank);
printf("%d\n",v[i].rank);
}
int main()
{
//freopen("test.in","r",stdin);
CA *a=new CA;
a->run();
return 0;
}
1056. Mice and Rice (25)
最新推荐文章于 2018-12-24 20:28:50 发布