题目描述
思路:本题为纯模拟题,按题目意思就好了。主要题目看的比较难受。然后如何用代码简洁实现比较关键。
#include
#include
#include
using namespace std;
const int N = 1100;
int weight[N],r[N];
vector<int> cur;
int main(){
int n,m;
cin>>n>>m;
for(int i = 0 ;i < n;i++) cin>>weight[i];
for(int i = 0;i < n;i++){
int a;
cin>>a;
cur.push_back(a);
}
while(cur.size() != 1){
int remain = (cur.size() - 1) / m + 1;
vector<int> next;
for(int k = 0;k < cur.size();){//k代表新一组开始的下标
int j = min(m+k,(int)cur.size());//新一组结束的下标
int t = k;
for(;k < j;k++){
if(weight[cur[k]] > weight[cur[t]])
t = k;
}
next.push_back(cur[t]);
}
for(auto i : cur)
r[i] = remain+1;
cur = next;
}
r[cur[0]] = 1;
cout<<r[0];
for(int i = 1;i < n;i++) cout<<" "<<r[i];
return 0;
}