[ZJOI2008]杀蚂蚁 Solution
题目太长,不在此显示,见洛谷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的更多相关文章
- Luogu2586 [ZJOI2008]杀蚂蚁 ---- 模拟
Luogu2586 [ZJOI2008]杀蚂蚁 题意 还是一道大模拟 https://www.luogu.org/problemnew/show/P2586 大概就是炮塔大蚂蚁的故事 下载这个游戏ht ...
- [BZOJ 1033][ZJOI2008]杀蚂蚁antbuster
1033: [ZJOI2008]杀蚂蚁antbuster Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1200 Solved: 507[Submi ...
- [ZJOI2008]杀蚂蚁antbuster
[ZJOI2008]杀蚂蚁antbuster 题目 最近,佳佳迷上了一款好玩的小游戏:antbuster.游戏规则非常简单:在一张地图上,左上角是蚂蚁窝,右下角是蛋糕,蚂蚁会源源不断地从窝里爬出来,试 ...
- P2586 [ZJOI2008]杀蚂蚁(模拟)
P2586 [ZJOI2008]杀蚂蚁 大模拟. 什么都不想补了. 看变量名感性理解吧 #include<iostream> #include<cstdio> #include ...
- BZOJ1033:[ZJOI2008]杀蚂蚁antbuster(模拟)
Description 最近,佳佳迷上了一款好玩的小游戏:antbuster.游戏规则非常简单:在一张地图上,左上角是蚂蚁窝,右 下角是蛋糕,蚂蚁会源源不断地从窝里爬出来,试图把蛋糕搬回蚂蚁窝.而你的 ...
- [bzoj1033] [ZJOI2008]杀蚂蚁antbuster
Description 最近,佳佳迷上了一款好玩的小游戏:antbuster.游戏规则非常简单:在一张地图上,左上角是蚂蚁窝,右下角是蛋糕,蚂蚁会源源不断地从窝里爬出来,试图把蛋糕搬回蚂蚁窝.而你的任 ...
- 【BZOJ 1033】 [ZJOI2008]杀蚂蚁antbuster
Description 最近,佳佳迷上了一款好玩的小游戏:antbuster.游戏规则非常简单:在一张地图上,左上角是蚂蚁窝,右下角是蛋糕,蚂蚁会源源不断地从窝里爬出来,试图把蛋糕搬回蚂蚁窝.而你的任 ...
- bzoj千题计划121:bzoj1033: [ZJOI2008]杀蚂蚁antbuster
http://www.lydsy.com/JudgeOnline/problem.php?id=1033 经半个下午+一个晚上+半个晚上 的 昏天黑地调代码 最终成果: codevs.洛谷.tyvj上 ...
- BZOJ1033:[ZJOI2008]杀蚂蚁
我对模拟的理解:https://www.cnblogs.com/AKMer/p/9064018.html 题目传送门:https://www.lydsy.com/JudgeOnline/problem ...
随机推荐
- Windows系统下如何在cmd命令窗口中切换Python2.7和Python3.6
针对在同一系统下我们可能安装多个版本的Python,毕竟Python2.7与Python3.6还是有不同的需求,但是在用Cmd命令窗口是我们可能默认的系统变量环境是其中一个版本,当我们需要在cmd命令 ...
- Antd 初识
mark 参考 antd - 官网:Ant Design Pro: Ant Design - github:Ant Design pro - github:
- 2016级算法期末上机-G.中等·Bamboo's Fight with DDLs II
中等·Bamboo's Fight with DDLs II 分析 一句话:给定字符串,求最长回文子序列长度,动态规划LCS思想的进阶应用 具体思路如下: 对于任意字符串,如果头尾字符相同,那么字符串 ...
- 蓝牙4.0BLE抓包(一) - 搭建EN-Dongle工作环境 使用EN-Dongle抓包 nRF51822
版权声明:本文为博主原创文章,转载请注明作者和出处. 蓝牙4.0 BLE的开发过程中,使用抓包器进行抓包分析无疑会极大地提高我们的开发效率,同时能帮我们快速的定位问题.对于初学者 ...
- linux centOS 7 GUI安装
centOS 7 GUI 图形用户界面(Graphical User Interface 克隆clone Windows中安装xshell和xftp传输软件 https://blog.csdn.net ...
- Java 子类父类构造方法执行顺序
public class Test { class Super { int flag = 1; Super() { test(); } void test() { System.out.println ...
- [转] 手动上传jar包到远程仓库 (maven deploy)
[From] https://my.oschina.net/360yg/blog/1588899 前言:通常允许上传的远程仓库有两种:Snapshots和Releases,分别为快照版仓库和稳定版仓库 ...
- C#多线程学习一
一.概述:C#支持多线程并行执行程序,一个线程有他单独的执行路径,能够与其他线程同时执行,一个程序是由一个单线程开始,该单线程由CLR(公共语言运行时)和操作系统创建而成,并具有多线程创建额外线程的功 ...
- vertical-aligin
垂直对齐元素只应用于行内元素(图像.文本)和表单元素 垂直对齐文本会影响行高 默认值为baseline
- Microsoft Power BI Desktop概念学习系列之Microsoft Power BI Desktop的官网自带示例数据(图文详解)
不多说,直接上干货! https://docs.microsoft.com/zh-cn/power-bi/sample-datasets 后续的博文系列,将进行深入的剖析和分享. 欢迎大家,加入我的微 ...