题目太长,不在此显示,见洛谷P2586

http://daniu.luogu.org/problem/show?pid=2586



模拟,

那就模拟呗;

各种WA,

然后好久才A了;

一种被社会报复了的感觉

好像被蚂蚁踩死了

代码能力太差

唉,正题:

整体流程:

1.蚂蚁出生;

2.放信息素;

3.到处乱跑;

4.被弄死;

5.结算;

6.(神允许)时间流动;

然后是一些细节:

1.输出的蚂蚁年龄,把刚出生的蚂蚁视为0岁,直到一次时间流动后才是1岁,然而与移动方向相关的年龄视刚出生的蚂蚁为1岁

2.可以伪链式存储蚂蚁,以方便查询

3.对于一只蚂蚁,如果她要移动,则不能移动回上回合呆的地方(上上回合呆的地方可以)

4.不移动的蚂蚁也有可能变成target----(上回合的target挂了,然后这只蚂蚁被卡在(n,m)点)

5.炮塔选定目标时,把蚂蚁看为点,然而结算一次攻击的波及范围时,把蚂蚁看做圆

6.半径0.5

7.炮塔同时选目标,同时攻击

8.仔细阅读如下文字:“只要目标在其射程内,塔到目标蚂蚁圆心的连线上的所有蚂蚁......”好像是说如果目标不在射程内,谁也不会被攻击

9.其他一些,诸如,信息素别减爆、血量别加超,之类的;

代码如下:(因为没有重构,所以代码十分难看)

 #include<cstdio>
using namespace std;
struct ANT{
int x,y,time,blo,blo_up,lv,lx,ly,next;
bool cake;
};
struct Tour{
int x,y;
};
ANT ant[];
int tot,many,target,top=;
Tour tour[];
int n,m,s,d,r,t;
int ma_su[][];
int ma_th[][];
int xx[]={,,,-};
int yy[]={,,-,};
void Init();
void work();
void born();
double Sqr(int );
void put_su();
void run();
void hurt();
bool cmp(int ,int ,int ,int ,int ,int );
bool check();
void print();
int main()
{
Init();
work();
}
void Init(){
int i,j,k;
scanf("%d%d",&n,&m);
scanf("%d%d%d",&s,&d,&r);
for(i=;i<=s;i++){
scanf("%d%d",&tour[i].x,&tour[i].y);
ma_th[tour[i].x][tour[i].y]=-;
}
scanf("%d",&t);
tot=many=target=;
return ;
}
void work(){
int i,j,T=;
while(++T<=t){
born();
put_su();
run();
hurt();
if(check()){
printf("Game over after %d seconds\n",T);
print();
return;
}
for(i=;i<=n;i++)
for(j=;j<=m;j++)
ma_su[i][j]-=(ma_su[i][j]!=?:);
for(i=;i<=tot;i++)
ant[i].time++;
}
printf("The game is going on\n");
print();
return;
}
void born(){
if(!ma_th[][]&&many<){
ant[top].next=++tot;
ant[tot].lv=(tot-)/+;
ant[tot].blo=ant[tot].blo_up=int(*Sqr(ant[tot].lv));
ant[tot].time=;
ant[tot].x=ant[tot].y=;ant[tot].lx=ant[tot].ly=-;
ma_th[][]=tot;
many++;
top=tot;
}
}
double Sqr(int m){
double ans=,x=1.1;
while(m){
if(m&)
ans*=x;
m>>=;
x*=x;
}
return ans;
}
void put_su(){
int i;
for(i=;i<=tot;i++)
if(ant[i].blo>=)
ma_su[ant[i].x][ant[i].y]+=(ant[i].cake?:);
}
void run(){
int i,j,k,fx,X,Y,max;
for(i=ant[].next;i;i=ant[i].next){
fx=-;max=-;
for(j=;j<=;j++){
X=ant[i].x+xx[j];
Y=ant[i].y+yy[j];
if(X<=n&&X>=&&Y<=m&&Y>=&&(X!=ant[i].lx||Y!=ant[i].ly)&&(!ma_th[X][Y])&&ma_su[X][Y]>max){
max=ma_su[X][Y];
fx=j;
}
}
if(fx!=-){
if(!((ant[i].time+)%))
for(j=;j<=;j++){
fx=(fx+-)%;
X=ant[i].x+xx[fx];
Y=ant[i].y+yy[fx];
if(X<=n&&X>=&&Y<=m&&Y>=&&(X!=ant[i].lx||Y!=ant[i].ly)&&(!ma_th[X][Y]))
break;
}
ma_th[ant[i].x][ant[i].y]=;
ant[i].lx=ant[i].x;ant[i].ly=ant[i].y;
ant[i].x+=xx[fx];ant[i].y+=yy[fx];
}
else{
ant[i].lx=-;
ant[i].ly=-;
}
if(ant[i].x==n&&ant[i].y==m&&!target){
target=i;
ant[i].cake=true;
ant[i].blo=ant[i].blo+ant[i].blo_up/<ant[i].blo_up?ant[i].blo+ant[i].blo_up/:ant[i].blo_up;
}
ma_th[ant[i].x][ant[i].y]=i;
}
}
void hurt(){
int i,j,k,len,targ=-,X,Y;
for(i=;i<=s;i++){
X=ant[target].x-tour[i].x;Y=ant[target].y-tour[i].y;
if(!target||X*X+Y*Y>r*r){
len=;
for(j=ant[].next;j;j=ant[j].next)
if((tour[i].x-ant[j].x)*(tour[i].x-ant[j].x)+(tour[i].y-ant[j].y)*(tour[i].y-ant[j].y)<len){
targ=j;len=(tour[i].x-ant[j].x)*(tour[i].x-ant[j].x)+(tour[i].y-ant[j].y)*(tour[i].y-ant[j].y);
}
}
else
targ=target;
X=ant[targ].x-tour[i].x;Y=ant[targ].y-tour[i].y;
if(X*X+Y*Y<=r*r)
for(j=ant[].next;j;j=ant[j].next)
if(cmp(ant[j].x,ant[j].y,tour[i].x,tour[i].y,ant[targ].x,ant[targ].y))
ant[j].blo-=d;
}
j=;
for(i=ant[j].next;i;i=ant[i].next)
if(ant[i].blo<){
ma_th[ant[i].x][ant[i].y]=;many--;
ant[j].next=ant[i].next;
if(i==target)
ant[i].cake=false;
if(i==top)
top=j;
}
else
j=i;
if(!ant[target].cake)
target=;
}
bool cmp(int ax,int ay,int tx,int ty,int targx,int targy){
double t_ax=ax-tx,t_ay=ay-ty,targ_ax=ax-targx,targ_ay=ay-targy,t_targx=targx-tx,t_targy=targy-ty;
double R=(t_ax*t_targx+t_ay*t_targy)/(t_targx*t_targx+t_targy*t_targy);
if(R<=)return (t_ax*t_ax+t_ay*t_ay)<=0.25;
if(R>=)return (targ_ax*targ_ax+targ_ay*targ_ay)<=0.25;
double px=tx+(targx-tx)*R;
double py=ty+(targy-ty)*R;
return (ax-px)*(ax-px)+(ay-py)*(ay-py)<=0.25;
}
bool check(){
return (target&&!ant[target].x&&!ant[target].y);
}
void print(){
int i;
printf("%d\n",many);
for(i=ant[].next;i;i=ant[i].next)
printf("%d %d %d %d %d\n",ant[i].time,ant[i].lv,ant[i].blo,ant[i].x,ant[i].y);
}

祝AC

[ZJOI2008]杀蚂蚁 Solution的更多相关文章

  1. Luogu2586 [ZJOI2008]杀蚂蚁 ---- 模拟

    Luogu2586 [ZJOI2008]杀蚂蚁 题意 还是一道大模拟 https://www.luogu.org/problemnew/show/P2586 大概就是炮塔大蚂蚁的故事 下载这个游戏ht ...

  2. [BZOJ 1033][ZJOI2008]杀蚂蚁antbuster

    1033: [ZJOI2008]杀蚂蚁antbuster Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1200  Solved: 507[Submi ...

  3. [ZJOI2008]杀蚂蚁antbuster

    [ZJOI2008]杀蚂蚁antbuster 题目 最近,佳佳迷上了一款好玩的小游戏:antbuster.游戏规则非常简单:在一张地图上,左上角是蚂蚁窝,右下角是蛋糕,蚂蚁会源源不断地从窝里爬出来,试 ...

  4. P2586 [ZJOI2008]杀蚂蚁(模拟)

    P2586 [ZJOI2008]杀蚂蚁 大模拟. 什么都不想补了. 看变量名感性理解吧 #include<iostream> #include<cstdio> #include ...

  5. BZOJ1033:[ZJOI2008]杀蚂蚁antbuster(模拟)

    Description 最近,佳佳迷上了一款好玩的小游戏:antbuster.游戏规则非常简单:在一张地图上,左上角是蚂蚁窝,右 下角是蛋糕,蚂蚁会源源不断地从窝里爬出来,试图把蛋糕搬回蚂蚁窝.而你的 ...

  6. [bzoj1033] [ZJOI2008]杀蚂蚁antbuster

    Description 最近,佳佳迷上了一款好玩的小游戏:antbuster.游戏规则非常简单:在一张地图上,左上角是蚂蚁窝,右下角是蛋糕,蚂蚁会源源不断地从窝里爬出来,试图把蛋糕搬回蚂蚁窝.而你的任 ...

  7. 【BZOJ 1033】 [ZJOI2008]杀蚂蚁antbuster

    Description 最近,佳佳迷上了一款好玩的小游戏:antbuster.游戏规则非常简单:在一张地图上,左上角是蚂蚁窝,右下角是蛋糕,蚂蚁会源源不断地从窝里爬出来,试图把蛋糕搬回蚂蚁窝.而你的任 ...

  8. bzoj千题计划121:bzoj1033: [ZJOI2008]杀蚂蚁antbuster

    http://www.lydsy.com/JudgeOnline/problem.php?id=1033 经半个下午+一个晚上+半个晚上 的 昏天黑地调代码 最终成果: codevs.洛谷.tyvj上 ...

  9. BZOJ1033:[ZJOI2008]杀蚂蚁

    我对模拟的理解:https://www.cnblogs.com/AKMer/p/9064018.html 题目传送门:https://www.lydsy.com/JudgeOnline/problem ...

随机推荐

  1. KMP算法再解 (看毛片算法真是人如其名,哦不,法如其名。)

    KMP算法主要解决字符串匹配问题,其中失配数组next很关键: 看毛片算法真是人如其名,哦不,法如其名. 看了这篇博客,转载过来看一波: 原博客地址:https://blog.csdn.net/sta ...

  2. sourceTree"重置提交"和"提交回滚"的区别

    相信用过sourceTree的伙伴们都认识这两,但是不一定用过这两个功能,甚至是不能很好的把握它两的区别,根据自己最近亲身测试,总算是能小小的总结一下了 首先这儿假如,历史版本已经出现了1.2.3.4 ...

  3. 编译原理(一)绪论概念&文法与语言

    绪论概念&文法与语言 以老师PPT为标准,借鉴部分教材内容,AlvinZH学习笔记. 绪论基本概念 1. 低级语言:字位码.机器语言.汇编语言.与特定的机器有关,功效高,但使用复杂.繁琐.费时 ...

  4. Android Studio如何配置adb以及常用命令

    https://blog.csdn.net/google_huchun/article/details/53314046 用Android Studio一年多了,都没有使用其调试adb,今天就分享ad ...

  5. webpack/gulp的z-index被改写

    webpack方法 new OptimizeCSSPlugin({ cssProcessorOptions: { safe: true } }) gulp-cssnano 方法 .pipe(cssna ...

  6. Compile git version inside go binary

    Compile git version inside go binary Abstract 在我们编写的程序中总是希望可以直接查阅程序的版本,通过--version参数就会输出如下版本信息. Buil ...

  7. Springsecurity搭建自定义登录页面

    1.springSecurity的搭建 新建一个springboot的web项目,我这边只选中了web,建立后如下: pom依赖: <!-- https://mvnrepository.com/ ...

  8. 深度学习(十三) R-CNN Fast RCNN

    object detection我的理解,就是在给定的图片中精确找到物体所在位置,并标注出物体的类别.object detection要解决的问题就是物体在哪里,是什么这整个流程的问题.然而,这个问题 ...

  9. InnoDB的B+树索引

    B+树索引其本质就是B+树在数据库中的实现,但是B+索引在数据库中有一个特点就是其高扇出性,因此在数据库中,B+树的高度一般都在2-3层,也就是对于查找某一键值的行记录,最多只需要2到3次IO,这倒不 ...

  10. [转载]二叉树(BST,AVT,RBT)

    二叉查找树(Binary Search Tree)是满足如下性质的二叉树:①若它的左子树非空,则左子树上所有结点的值均小于根结点的值:②若它的右子树非空,则右子树上所有结点的值均大于根结点的值:③左. ...