题目太长,不在此显示,见洛谷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. 谷歌将对欧洲 Android 设备制造商收取其应用服务费用

    简评:欧盟就谷歌违反了<反垄断法>开出天价罚单,导致谷歌运营生态被打破,为了配合这一裁决,谷歌将调整其运营模式.欧盟似乎赢了,而这最后买单的却是消费者. 今年七月份,谷歌要求 Androi ...

  2. log 模块使用 (直接用的方法)

    前情提要: 生活中经常用到log 模块. 但是原生的log 模块复杂或者有许多不好用得地方, 在此记录一个经常用的log 的基本操作方法 一:首先导入模块 import logging.config ...

  3. 2016级算法期末模拟练习赛-A.wuli51和京导的毕业旅行

    1063 wuli51和京导的毕业旅行 思路 中等题,二分+贪心. 简化题意,将m+1个数字分成n份,ans为这n段中每段数字和的最大值,求ans最小值及其方案. 对于这种求最小的最大值,最常用的方法 ...

  4. RDD转换成为DataFrame

    方式一: 通过case class创建DataFrames(反射) TestDataFrame1.scala package com.bky // 隐式类的导入 // 定义case class,相当于 ...

  5. jQuery css()与class()的用法

    一.css()用法:   1.设置css // css(name, value) // 修改单个样式 // name:样式名 value:样式值 $("li") .css(&quo ...

  6. 【性能压测】:MQ队列异步处理机制导致的系统无法接受请求的问题

    一,最近压测系统交易峰值时,因该支交易采用MQ异步队列处理机制:该增加积分的交易,前段服务器优先返回给客户增加积分成功的结果,后端的MQ队列服务器再慢慢处理该请求: 二,压测过程中出现的问题现象:前几 ...

  7. mvvm小论(暂记)

    广州-PC26(34627) 2:09:44 在android 线程最后用 handler = new Handler();            updateThread = new Runnabl ...

  8. ECharts-入门学习

    最近因项目需要要做图表,后台数据要以柱状图的形式展示,通过上网查找,感觉ECharts这个js控件挺不错的,下面就把入门知识搞一下. 一.下载ECharts控件. 地址:http://echarts. ...

  9. spring boot快速入门 9: 单元测试

    进行单元测试: service第一种方式: 第一步:在指定service中创建一个方法进行测试 /** * 通过ID查询一个女生的信息 * @param id * @return */ public ...

  10. php 如何匹配中文或英文姓名

    这几天在做项目的用户注册时,想限制用户使用一些比较奇怪的字符作为名字,即使用中文或者英文名字. 查了一些资料,例如:网友挥得更高的百度空间 写下了以下函数. //验证名字和密码 if (!preg_m ...