1056 Mice and Rice (25)-分析:模拟比赛即可。注意第一次比赛是按照给定的顺序进行,之后的比赛是按照每次晋级老鼠的位置进行。

时间:2024-11-18 07:38:08
#include<algorithm>
#include <iostream>
#include  <cstdlib>
#include  <cstring>
#include   <string>
#include   <vector>
#include   <cstdio>
#include    <queue>
#include    <stack>
#include    <ctime>
#include    <cmath>
#include      <map>
#include      <set>
#define INF 0xffffffff
#define db1(x) cout<<#x<<"="<<(x)<<endl
#define db2(x,y) cout<<#x<<"="<<(x)<<", "<<#y<<"="<<(y)<<endl
#define db3(x,y,z) cout<<#x<<"="<<(x)<<", "<<#y<<"="<<(y)<<", "<<#z<<"="<<(z)<<endl
#define db4(x,y,z,r) cout<<#x<<"="<<(x)<<", "<<#y<<"="<<(y)<<", "<<#z<<"="<<(z)<<", "<<#r<<"="<<(r)<<endl
using namespace std;

typedef struct
{
    int weight,ind;
}mice;

int main(void)
{
    #ifdef test
    freopen("in.txt","r",stdin);
    //freopen("in.txt","w",stdout);
    clock_t start=clock();
    #endif //test

    int np,ng;scanf("%d%d",&np,&ng);
    mice num[np],cnt[np];
    int ans[np]={0},que[np]={0};
    int t=np;
    for(int i=0;i<np;++i)
        scanf("%d",&num[i].weight),num[i].ind=i;
    for(int i=0;i<np;++i)
        scanf("%d",&que[i]);

    int tt=0;
    int ind=0,val;
    if(t%ng!=0)val=t/ng+2;
    else val=t/ng+1;
    for(int i=0;i<t;i=i+ng)
    {
        int temp=num[que[i]].weight,index=i,r=min(i+ng,t);
        for(int j=i+1;j<r;++j)
        {
            if(num[que[j]].weight>temp)temp=num[que[j]].weight,index=j;
        }
        for(int j=i;j<r;++j)
        {
            if(j!=index)ans[num[que[j]].ind]=val;
        }
        cnt[tt]=num[que[index]];
        tt++;
    }
    t=tt,tt=0;
    for(int i=0;i<t;++i)
        num[i]=cnt[i];

    while(t>1)
    {
        ind=0;
        if(t%ng!=0)val=t/ng+2;
        else val=t/ng+1;

        for(int i=0;i<t;i=i+ng)
        {
            int temp=num[i].weight,index=i,r=min(i+ng,t);
            for(int j=i+1;j<r;++j)
            {
                if(num[j].weight>temp)temp=num[j].weight,index=j;
            }
            for(int j=i;j<r;++j)
            {
                if(j!=index)ans[num[j].ind]=val;
            }
            cnt[tt]=num[index];
            tt++;
        }
        for(int i=0;i<tt;++i)
            num[i]=cnt[i];
        t=tt,tt=0;
    }
    ans[num[0].ind]=1;
    for(int i=0;i<np;++i)
    {
        if(!i)printf("%d",ans[i]);
        else printf(" %d",ans[i]);
    }
    printf("\n");

    #ifdef test
    clockid_t end=clock();
    double endtime=(double)(end-start)/CLOCKS_PER_SEC;
    printf("\n\n\n\n\n");
    cout<<"Total time:"<<endtime<<"s"<<endl;        //s为单位
    cout<<"Total time:"<<endtime*1000<<"ms"<<endl;    //ms为单位
    #endif //test
    return 0;
}