• [bzoj1033] [ZJOI2008]杀蚂蚁 Big MoNI


    这个模拟就不用说了吧......

    注意事项(救命的):1.不能回原位 2.在可以打到target的塔打target的时候,其他打不到的继续打自己的(这是显然的事情只是当时已惘然) 3.如果游戏在某一秒结束,那么这一秒年龄不加 4.蚂蚁半径0.5 5.蚂蚁窝上不能有蚂蚁 6.HP别加爆,信息素别减爆 7.如果一只蚂蚁被卡了那么他也可能是被卡在蛋糕那里,也就是上一个死了,他被卡了,他就拿到了

    #include<cstdio>
    #include<cstring>
    #include<iostream>
    #include<cstdlib>
    #include<cmath>
    using namespace std;
    inline int read()
    {
        int sum=0;
        char ch=getchar();
        while(ch<'0'||ch>'9')ch=getchar();
        while(ch>='0'&&ch<='9')
        {
            sum=(sum<<1)+(sum<<3)+ch-'0';
            ch=getchar();
        }
        return sum;
    }
    typedef long double LD;
    LD Source_HP[250];
    const LD eps=1e-12;
    int Now_Rank=1,Rank_In;
    int Information[25][25];
    int pos[25][25];
    int s,d,r;
    int target;
    struct Ant
    {
        int S_HP,HP,x,y,old,id,X,Y;
    }ant[10];
    struct Tor
    {
        int x,y;
    }tor[25];
    int t,T,n,m;
    int ant_now;
    int go1[4]={0,1,0,-1};
    int go2[4]={1,0,-1,0};
    inline void Read()
    {
        n=read(),m=read(),s=read(),d=read(),r=read();
        for(int i=1;i<=s;i++)tor[i].x=read(),tor[i].y=read(),pos[tor[i].x][tor[i].y]=2;
        T=read();
        Source_HP[0]=4.0;
        for(int i=1;i<250;i++)Source_HP[i]=Source_HP[i-1]*1.1;
    }
    inline int SQR(int x)
    {
        return x*x;
    }
    inline LD Sqr(LD x)
    {
        return x*x;
    }
    int main()
    {
       Read();
       while(t<T)
       {
           ++t;
           if(ant_now<6&&(pos[0][0]==0))
           {
               ++ant_now;
               ant[ant_now].x=ant[ant_now].y=ant[ant_now].old=0;
               ant[ant_now].X=ant[ant_now].Y=-1;
               pos[0][0]=1;
               ant[ant_now].S_HP=ant[ant_now].HP=(int)(Source_HP[Now_Rank]);
               ant[ant_now].id=Now_Rank;
               ++Rank_In;
               if(Rank_In==6)
                 Rank_In=0,++Now_Rank;
           }
           for(int i=1;i<=ant_now;i++)Information[ant[i].x][ant[i].y]+=(i==target)?5:2;
           for(int i=1;i<=ant_now;i++)
           {
               int to=-1,key=-1;
               if(ant[i].y!=m&&pos[ant[i].x+go1[0]][ant[i].y+go2[0]]==0&&Information[ant[i].x+go1[0]][ant[i].y+go2[0]]>key&&((ant[i].x+go1[0]==ant[i].X&&ant[i].y+go2[0]==ant[i].Y)==0))
                to=0,key=Information[ant[i].x+go1[0]][ant[i].y+go2[0]];
               if(ant[i].x!=n&&pos[ant[i].x+go1[1]][ant[i].y+go2[1]]==0&&Information[ant[i].x+go1[1]][ant[i].y+go2[1]]>key&&((ant[i].x+go1[1]==ant[i].X&&ant[i].y+go2[1]==ant[i].Y)==0))
                to=1,key=Information[ant[i].x+go1[1]][ant[i].y+go2[1]];
               if(ant[i].y!=0&&pos[ant[i].x+go1[2]][ant[i].y+go2[2]]==0&&Information[ant[i].x+go1[2]][ant[i].y+go2[2]]>key&&((ant[i].x+go1[2]==ant[i].X&&ant[i].y+go2[2]==ant[i].Y)==0))
                to=2,key=Information[ant[i].x+go1[2]][ant[i].y+go2[2]];
               if(ant[i].x!=0&&pos[ant[i].x+go1[3]][ant[i].y+go2[3]]==0&&Information[ant[i].x+go1[3]][ant[i].y+go2[3]]>key&&((ant[i].x+go1[3]==ant[i].X&&ant[i].y+go2[3]==ant[i].Y)==0))
                to=3,key=Information[ant[i].x+go1[3]][ant[i].y+go2[3]];
               if(to==-1)
               {
                   ant[i].X=ant[i].x;
                   ant[i].Y=ant[i].y;
                   if(target==0&&ant[i].x==n&&ant[i].y==m)
                      target=i,ant[i].HP=(ant[i].HP+(ant[i].S_HP>>1))>=ant[i].S_HP?ant[i].S_HP:(ant[i].HP+(ant[i].S_HP>>1));
                   continue;
               }
               if((ant[i].old+1)%5==0)
               {
                   to=(to==0)?3:(to-1);
                   while(1)
                    if(ant[i].x+go1[to]>=0&&ant[i].x+go1[to]<=n&&ant[i].y+go2[to]>=0&&ant[i].y+go2[to]<=m&&pos[ant[i].x+go1[to]][ant[i].y+go2[to]]==0&&(ant[i].x+go1[to]==ant[i].X&&ant[i].y+go2[to]==ant[i].Y)==0)
                     break;
                    else
                     to=(to==0)?3:(to-1);
               }
               ant[i].X=ant[i].x;
               ant[i].Y=ant[i].y;
               pos[ant[i].x+go1[to]][ant[i].y+go2[to]]=1;
               pos[ant[i].x][ant[i].y]=0;
               if(target==0&&ant[i].x+go1[to]==n&&ant[i].y+go2[to]==m)
                target=i,ant[i].HP=(ant[i].HP+(ant[i].S_HP>>1))>=ant[i].S_HP?ant[i].S_HP:(ant[i].HP+(ant[i].S_HP>>1));
               ant[i].x=ant[i].x+go1[to];
               ant[i].y=ant[i].y+go2[to];
           }
           if(target)
           {
                for(int i=1;i<=s;i++)
                  if(SQR(ant[target].x-tor[i].x)+SQR(ant[target].y-tor[i].y)<=SQR(r))
                  {
                    int a=ant[target].y-tor[i].y,b=tor[i].x-ant[target].x,c=tor[i].y*(ant[target].x-tor[i].x)+tor[i].x*(tor[i].y-ant[target].y);
                    if(b!=0)
                    {
                      LD Ki=0.0-(LD)a/b,Bi=0.0-(LD)c/b;
                      int l=ant[target].x<tor[i].x?ant[target].x:tor[i].x,r=ant[target].x>tor[i].x?ant[target].x:tor[i].x;
                      for(int j=1;j<=ant_now;j++)
                      if(SQR(a*ant[j].x+b*ant[j].y+c)<=0.25*(SQR(a)+SQR(b)))
                      {
                         LD A=(1.0+Sqr(Ki)),B=2.0*Ki*(Bi-ant[j].y)-2.0*ant[j].x,C=Sqr(Bi-ant[j].y)+Sqr(ant[j].x)-0.25;
                         LD X1=(-B-sqrt(Sqr(B)-4.0*A*C))/(2.0*A),X2=(-B+sqrt(Sqr(B)-4.0*A*C))/(2.0*A);
                         if((l-eps<=X1&&r+eps>=X1)||(l-eps<=X2&&r+eps>=X2))ant[j].HP-=d;
                      }
                    }
                    else
                    {
                      LD Ni=(LD)c/a;
                      int l=ant[target].y<tor[i].y?ant[target].y:tor[i].y,r=ant[target].y>tor[i].y?ant[target].y:tor[i].y;
                      for(int j=1;j<=ant_now;j++)
                      if(SQR(a*ant[j].x+b*ant[j].y+c)<=0.25*(SQR(a)+SQR(b)))
                      {
                        LD A=1.0,B=-2.0*ant[j].y,C=Sqr(ant[j].y)+Sqr(Ni+ant[j].x)-0.25;
                        LD X1=(-B-sqrt(Sqr(B)-4.0*A*C))/(2.0*A),X2=(-B+sqrt(Sqr(B)-4.0*A*C))/(2.0*A);
                        if((l-eps<=X1&&r+eps>=X1)||(l-eps<=X2&&r+eps>=X2))ant[j].HP-=d;
                      }
                    }
                  }
                  else
                  {
                      int temp=target;
                      int dis=0x7fffffff;
                      for(int j=1;j<=ant_now;j++)
                       if(SQR(ant[j].x-tor[i].x)+SQR(ant[j].y-tor[i].y)<dis)
                        target=j,dis=SQR(ant[j].x-tor[i].x)+SQR(ant[j].y-tor[i].y);
                      if(SQR(ant[target].x-tor[i].x)+SQR(ant[target].y-tor[i].y)<=SQR(r))
                      {
                       int a=ant[target].y-tor[i].y,b=tor[i].x-ant[target].x,c=tor[i].y*(ant[target].x-tor[i].x)+tor[i].x*(tor[i].y-ant[target].y);
                       if(b!=0)
                       {
                          LD Ki=0.0-(LD)a/b,Bi=0.0-(LD)c/b;
                          int l=ant[target].x<tor[i].x?ant[target].x:tor[i].x,r=ant[target].x>tor[i].x?ant[target].x:tor[i].x;
                          for(int j=1;j<=ant_now;j++)
                          if(SQR(a*ant[j].x+b*ant[j].y+c)<=0.25*(SQR(a)+SQR(b)))
                          {
                             LD A=(1.0+Sqr(Ki)),B=2.0*Ki*(Bi-ant[j].y)-2.0*ant[j].x,C=Sqr(Bi-ant[j].y)+Sqr(ant[j].x)-0.25;
                             LD X1=(-B-sqrt(Sqr(B)-4.0*A*C))/(2.0*A),X2=(-B+sqrt(Sqr(B)-4.0*A*C))/(2.0*A);
                             if((l-eps<=X1&&r+eps>=X1)||(l-eps<=X2&&r+eps>=X2))ant[j].HP-=d;
                          }
                       }
                       else
                       {
                            LD Ni=(LD)c/a;
                            int l=ant[target].y<tor[i].y?ant[target].y:tor[i].y,r=ant[target].y>tor[i].y?ant[target].y:tor[i].y;
                            for(int j=1;j<=ant_now;j++)
                            if(SQR(a*ant[j].x+b*ant[j].y+c)<=0.25*(SQR(a)+SQR(b)))
                            {
                                LD A=1.0,B=-2.0*ant[j].y,C=Sqr(ant[j].y)+Sqr(Ni+ant[j].x)-0.25;
                                LD X1=(-B-sqrt(Sqr(B)-4.0*A*C))/(2.0*A),X2=(-B+sqrt(Sqr(B)-4.0*A*C))/(2.0*A);
                                if((l-eps<=X1&&r+eps>=X1)||(l-eps<=X2&&r+eps>=X2))ant[j].HP-=d;
                            } 
                        }
                      }
                      target=temp;
                  }
           }
           else
           {
               for(int i=1;i<=s;i++)
               {
                 int dis=0x7fffffff;
                 for(int j=1;j<=ant_now;j++)
                  if(SQR(ant[j].x-tor[i].x)+SQR(ant[j].y-tor[i].y)<dis)
                   target=j,dis=SQR(ant[j].x-tor[i].x)+SQR(ant[j].y-tor[i].y);
                 if(SQR(ant[target].x-tor[i].x)+SQR(ant[target].y-tor[i].y)<=SQR(r))
                 {
                   int a=ant[target].y-tor[i].y,b=tor[i].x-ant[target].x,c=tor[i].y*(ant[target].x-tor[i].x)+tor[i].x*(tor[i].y-ant[target].y);
                   if(b!=0)
                   {
                      LD Ki=0.0-(LD)a/b,Bi=0.0-(LD)c/b;
                      int l=ant[target].x<tor[i].x?ant[target].x:tor[i].x,r=ant[target].x>tor[i].x?ant[target].x:tor[i].x;
                      for(int j=1;j<=ant_now;j++)
                      if(SQR(a*ant[j].x+b*ant[j].y+c)<=0.25*(SQR(a)+SQR(b)))
                      {
                          LD A=(1.0+Sqr(Ki)),B=2.0*Ki*(Bi-ant[j].y)-2.0*ant[j].x,C=Sqr(Bi-ant[j].y)+Sqr(ant[j].x)-0.25;
                          LD X1=(-B-sqrt(Sqr(B)-4.0*A*C))/(2.0*A),X2=(-B+sqrt(Sqr(B)-4.0*A*C))/(2.0*A);
                          if((l-eps<=X1&&r+eps>=X1)||(l-eps<=X2&&r+eps>=X2))ant[j].HP-=d;
                      }
                   }
                   else
                   {
                      LD Ni=(LD)c/a;
                      int l=ant[target].y<tor[i].y?ant[target].y:tor[i].y,r=ant[target].y>tor[i].y?ant[target].y:tor[i].y;
                      for(int j=1;j<=ant_now;j++)
                      if(SQR(a*ant[j].x+b*ant[j].y+c)<=0.25*(SQR(a)+SQR(b)))
                      {
                          LD A=1.0,B=-2.0*ant[j].y,C=Sqr(ant[j].y)+Sqr(Ni+ant[j].x)-0.25;
                          LD X1=(-B-sqrt(Sqr(B)-4.0*A*C))/(2.0*A),X2=(-B+sqrt(Sqr(B)-4.0*A*C))/(2.0*A);
                          if((l-eps<=X1&&r+eps>=X1)||(l-eps<=X2&&r+eps>=X2))ant[j].HP-=d;
                      }
                  }
                 }
                 target=0;
             }
           }
           bool god=0;
           int temp=ant_now;
           ant_now=0;
           for(int i=1;i<=temp;i++)
            if(ant[i].HP<0)
            { 
                if(i==target) target=0; 
                pos[ant[i].x][ant[i].y]=0;
            }
            else
            {
                if(i==target)
                {
                    if(ant[i].x==0&&ant[i].y==0) god=1;
                    target=ant_now+1;
                }
                ant[++ant_now]=ant[i];
            }
           for(int i=0;i<=n;i++)
            for(int j=0;j<=m;j++)
             if(Information[i][j])--Information[i][j];
           if(god)
           {
               printf("Game over after %d seconds
    ",t);
               printf("%d
    ",ant_now);
               for(int i=1;i<=ant_now;i++)
                printf("%d %d %d %d %d
    ",ant[i].old,ant[i].id,ant[i].HP,ant[i].x,ant[i].y);
               return 0;
           }
           for(int i=1;i<=ant_now;i++)++ant[i].old;
       }
       printf("The game is going on
    ");
       printf("%d
    ",ant_now);
       for(int i=1;i<=ant_now;i++)
        printf("%d %d %d %d %d
    ",ant[i].old,ant[i].id,ant[i].HP,ant[i].x,ant[i].y);
       return 0;
    }
  • 相关阅读:
    博弈论《《转》》
    HDU 2509 Be the Winner
    SORT排序。。
    HDU 356 SNim
    博弈
    KM算法。《转载》以后看。
    jmeter(28)逻辑控制器 之 交替控制器
    jmeter(30)逻辑控制器 之 Switch Controller 暂时不写!
    jmeter(29)逻辑控制器 之 吞吐量控制器
    Shell一个文件并等待完成
  • 原文地址:https://www.cnblogs.com/TSHugh/p/7237450.html
Copyright © 2020-2023  润新知