洛谷P5506 封锁(模拟)

想练模拟又不想写猪国杀的话,这题是个不错的练手题比猪国杀好写不止一点点

#include<cstdio>
const int dx[8]={1,1,0,-1,-1,-1,0,1};
const int dy[8]={0,1,1,1,0,-1,-1,-1};
struct plane{
    int hp,atk,def,mat,mdf,fix,f,h,x,y,z;
    char s[105];
}a[105];
int tx,ty,tz;
inline int Max(int a,int b){return a>b?a:b;}
inline int max3(int a,int b,int c){return Max(a,Max(b,c));}
inline void getmov(int p){
    if(!a[p].h||a[p].h==4){tx=ty=0;tz=!a[p].h?-1:1;}
    else{
        tx=dx[a[p].f];ty=dy[a[p].f];
        if(a[p].h==2)tz=0;
        else tz=a[p].h==1?-1:1;
    }
}
inline bool getdis(int a,int x,int &d){
    if(!x){
        d=-1;
        return !a;
    }
    d=a*x;
    return d>0;
}
int main(){
    int n,t,i,j,k,p,pd,d1,d2,d3;
    scanf("%d%d",&n,&t);
    for(i=1;i<=n;++i)scanf("%d%d%d%d%d%d%d%d%d%d%d%s",&a[i].x,&a[i].y,&a[i].z,&a[i].h,&a[i].f,&a[i].atk,&a[i].def,&a[i].mat,&a[i].mdf,&a[i].hp,&a[i].fix,a[i].s);
    for(i=0;i<t;++i){
        for(j=1;j<=n;++j)if(a[j].hp){
            getmov(j);
            a[j].x+=tx;a[j].y+=ty;a[j].z+=tz;
        }
        for(j=1;j<=n;++j)if(a[j].hp)if(a[j].s[i]=='U')if(a[j].h<4)++a[j].h;
        else;
        else if(a[j].s[i]=='D')if(a[j].h)--a[j].h;
        else;
        else if(a[j].s[i]=='L')a[j].f=(a[j].f+1)&7;
        else if(a[j].s[i]=='R')a[j].f=(a[j].f+7)&7;
        else if(a[j].s[i]=='F')a[j].hp+=a[j].fix;
        else{
            getmov(j);
            if(a[j].s[i]=='A'){
                for(p=0,k=1,pd=0x3f3f3f3f;k<=n;++k)if(k!=j&&a[k].hp){
                    if(!getdis(a[k].x-a[j].x,tx,d1)||!getdis(a[k].y-a[j].y,ty,d2)||!getdis(a[k].z-a[j].z,tz,d3))continue;
                    if(d1!=-1)if(d2!=-1)if(d3!=-1)if(d1!=d2||d1!=d3)continue;
                    else;
                    else if(d1!=d2)continue;
                    else;
                    else if(d3!=-1)if(d1!=d3)continue;
                    else;
                    else;
                    else if(d2!=-1&&d3!=-1&&d2!=d3)continue;
                    if(max3(d1,d2,d3)<pd){p=k;pd=max3(d1,d2,d3);}
                }
                if(p)a[p].hp=Max(0,a[p].hp-Max(0,a[j].atk-a[p].def));
            }else if(a[j].s[i]=='M')for(k=1;k<=n;++k)if(k!=j&&a[k].hp){
                if(!getdis(a[k].x-a[j].x,tx,d1)||!getdis(a[k].y-a[j].y,ty,d2)||!getdis(a[k].z-a[j].z,tz,d3))continue;
                if(d1!=-1)if(d2!=-1)if(d3!=-1)if(d1!=d2||d1!=d3)continue;
                else;
                else if(d1!=d2)continue;
                else;
                else if(d3!=-1)if(d1!=d3)continue;
                else;
                else;
                else if(d2!=-1&&d3!=-1&&d2!=d3)continue;
                a[k].hp=Max(0,a[k].hp-Max(0,a[j].mat-a[k].mdf));
            }
        }
    }
    for(i=1;i<=n;++i)printf("%d %d %d %d\n",a[i].x,a[i].y,a[i].z,a[i].hp);
    return 0;
}
View Code

 

posted @ 2019-08-14 15:20  wangyuchen  阅读(120)  评论(0编辑  收藏  举报