题目太长,不在此显示,见洛谷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. time 模块学习

    前情提要: time模块是经常使用的模块.主要是用来记录时间,以及时间上的相关操作 一:时间戳 1:第一种形式 import time print(time.time()) 从1970 1 1 0:0 ...

  2. canvas+js+面向对象的矩形封装

    效果: Rect.js /* 1. 封装属性: x, y w , h, fillStyle strokeStyle rotation opacity 2.render */ function Rect ...

  3. python学习,day4:装饰器的使用示例2

    这个例子比较复杂 # coding=utf-8 # Author: RyAn Bi user,passwd = ' #输入用户名密码 def auth(auth_type): #装饰器第一层,确定鉴权 ...

  4. WCF系列教程之WCF服务宿主与WCF服务部署

    本文参考自http://www.cnblogs.com/wangweimutou/p/4377062.html,纯属读书笔记,加深记忆. 一.简介 任何一个程序的运行都需要依赖一个确定的进程中,WCF ...

  5. redis 数据类型 Hash

    Redis 数据类型Hash:hash数据类型存储的数据和mysql数据库中存储的一条记录很类似. hash的一些操作: 比如数据库是user表,有id,name,age ,sex,可以建立与之对应的 ...

  6. JavaScript设计模式-15.适配器模式

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  7. docker私有仓库搭建及认证

    什么是docker? Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的 Linux 机器上,也可以实现虚拟化.容器是完全使用沙箱机 ...

  8. 多线程编程(四)-CyclicBarrier的使用

    CyclicBarrier的介绍 类CyclicBarrier不仅有CountDownLatch所具有的功能,还可以是啊县屏障等待的功能,也就是阶段性同步,它在使用上的意义在与可以循环地实现线程要一起 ...

  9. 多线程编程(二)-Exchanger的使用

    Exchanger的介绍 类Exchanger的功能可以使两个线程之间传输数据. 方法exchange()的使用 package com.wjg.unit; import java.util.conc ...

  10. 剑指offer(11-20)编程题

    二进制中1的个数 数值的整数次方 调整数组顺序使奇数位于偶数前面 链表中倒数第k个结点 反转链表 合并两个排序的链表 树的子结构 二叉树的镜像 顺时针打印矩阵 包含min函数的栈 11.输入一个整数, ...