记录编号 458615 评测结果 AAAAAAAAAA
题目名称 [ZJOI 2008] 杀蚂蚁 (完整版) 最终得分 100
用户昵称 GravatarHzoi_QTY 是否通过 通过
代码语言 C++ 运行时间 0.239 s
提交时间 2017-10-11 16:52:24 内存使用 3.33 MiB
显示代码纯文本
#include <cstdlib>
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#define N 200005
#define fl float
using namespace std;
struct zb
{
	int x,y;
	friend bool operator ==(zb a,zb b){
		if(a.x==b.x&&a.y==b.y)return 1;
		return 0;
	}
	zb(){}
	zb(int x_,int y_){x=x_;y=y_;}
}bomb[25],Cake,Cave;
struct Ant{int t,old,blood,lv;zb last,now;}ant[N];
int n,m,t,hurt,r,sum_b,nex[N],fro[N];//s->炮塔数量,d->伤害,r->攻击半径
int ant_sum,ant_now,boss;
int smell[10][10],map[10][10];//1->ant,2->bomb,3->cake
int turn[4][2]={0,1,1,0,0,-1,-1,0};
fl level[100000];
int hahaha(int x)
{
	int l=level[ant[x].lv];
	ant[x].blood+=l/2;
	if(ant[x].blood>l)ant[x].blood=l;
}
void delieve(int T)
{
	if(map[0][0])return;
	int l=++ant_now,v=(l-1)/6+1;
	ant_sum++;map[0][0]=1;
	ant[l].now=zb(0,0); ant[l].last=zb(-1,-1);
	ant[l].t=T; ant[l].old=1; 
	ant[l].blood=level[v]; ant[l].lv=v;
}
bool check(zb x,zb last)
{
	if(x.x<0||x.x>n||x.y<0||x.y>m)return 0;
	if(map[x.x][x.y]!=0)return 0;
	if(x==last)return 0;
	return 1;
}
void mad_turn(int x,int To,zb zz)
{
	for(int i=To-1;;i--)
	{
		if(i<0)i=3;
		zb to=zb(ant[x].now.x+turn[i][0],ant[x].now.y+turn[i][1]);
		if(check(to,zz)==1){ant[x].now=to;return;}
	}
}
void move(int x)
{
	int To=4,infor=-1;zb zz=ant[x].last;ant[x].last=ant[x].now;
	for(int i=0;i<4;i++)
	{
		zb to=zb(ant[x].now.x+turn[i][0],ant[x].now.y+turn[i][1]);
		if(!check(to,zz))continue;
		if(smell[to.x][to.y]>infor)To=i,infor=smell[to.x][to.y];
	}
	if(To==4)
	{	
		if(!boss&&Cake==ant[x].now){boss=x;hahaha(x);}
		if(boss==x)Cake=ant[x].now;
		map[ant[x].last.x][ant[x].last.y]=0;
		map[ant[x].now.x][ant[x].now.y]=1;
		return;
	}
	if(ant[x].old%5==0)mad_turn(x,To,zz);
	else ant[x].now=zb(ant[x].now.x+turn[To][0],ant[x].now.y+turn[To][1]);
	if(!boss&&Cake==ant[x].now){boss=x;hahaha(x);}
	if(boss==x)Cake=ant[x].now;
	map[ant[x].last.x][ant[x].last.y]=0;
	map[ant[x].now.x][ant[x].now.y]=1;
}	
void smellchange()
{
	for(int i=0;i<=n;i++)
		for(int j=0;j<=m;j++)
			if(smell[i][j]!=0)smell[i][j]--;
}
void dead(int x)
{
	nex[fro[x]]=nex[x];fro[nex[x]]=fro[x];
	ant_sum--;map[ant[x].now.x][ant[x].now.y]=0;
	if(boss==x){boss=0;Cake=zb(n,m);}
}
fl get_l(zb x,zb y){return (fl)sqrt(pow(x.x-y.x,2)+pow(x.y-y.y,2));}
fl MDZZ(fl a,fl b,fl c,zb x){return abs((fl)a*x.x+b*x.y+c)/sqrt(a*a+b*b);}
void get_hurt(zb x,zb y)
{
	int x1=max(x.x,y.x),x2=min(x.x,y.x),y1=max(x.y,y.y),y2=min(x.y,y.y);
	fl a,b,c;
	a=y.y-x.y; b=x.x-y.x; c=y.x*x.y-x.x*y.y;
	for(int i=nex[0];i<=ant_now;i=nex[i])
	{
		zb now=ant[i].now;
		if(now.x<x2||now.x>x1||now.y>y1||now.y<y2)continue;
		fl len=MDZZ(a,b,c,now);
		if(len>0.5)continue;
		ant[i].blood-=hurt;
	}
}
int which(int x)
{
	fl L=1000;int to=0;
	for(int i=nex[0];i<=ant_now;i=nex[i])
	{
		fl l=get_l(bomb[x],ant[i].now);
		if(l>(fl)r)continue;
		if(i==boss)return i;
		if(l<L)L=l,to=i;
	}
	return to;
}
void attack(int x)
{
	int to=which(x);
	if(to!=0)get_hurt(bomb[x],ant[to].now);
}
int play()
{
	for(int u=1;u<=t;u++)
	{
		if(ant_sum!=6)delieve(u);
		for(int i=nex[0];i<=ant_now;i=nex[i])
		{
			if(boss!=i)smell[ant[i].now.x][ant[i].now.y]+=2;
			else smell[ant[i].now.x][ant[i].now.y]+=5;
		}
		for(int i=nex[0];i<=ant_now;i=nex[i])move(i);
		for(int i=1;i<=sum_b;i++)attack(i);
		for(int i=nex[0];i<=ant_now;i=nex[i])
			if(ant[i].blood<0)dead(i);
		smellchange();
		if(Cake==Cave)return u;
		for(int i=nex[0];i<=ant_now;i=nex[i])ant[i].old++;
	}
	return 0;
}
void init()
{
	scanf("%d%d%d%d%d",&n,&m,&sum_b,&hurt,&r);
	for(int i=1;i<=sum_b;i++)
		scanf("%d%d",&bomb[i].x,&bomb[i].y),map[bomb[i].x][bomb[i].y]=2;
	scanf("%d",&t);
	ant_now=ant_sum=boss=0;
	Cake=zb(n,m);Cave=zb(0,0);
	for(int i=1;i<=t;i++)nex[i]=i+1,fro[i]=i-1;nex[0]=1;
	int l=(t-1)/6+1;level[0]=4;
	for(int i=1;i<=l;i++)level[i]=level[i-1]*1.1;
}
void jieshu()
{
	int hh=play();
	if(!hh)printf("The game is going on\n");
	else printf("Game over after %d seconds\n",hh);
	printf("%d\n",ant_sum);int s=0;
	for(int i=nex[0];i<=ant_now;i=nex[i])
		printf("%d %d %d %d %d\n",ant[i].old-1,ant[i].lv,ant[i].blood,ant[i].now.x,ant[i].now.y);
}
int yjn()
{
	freopen("antbuster_ex.in","r",stdin);
	freopen("antbuster_ex.out","w",stdout);
	init();jieshu();
}
int qty=yjn();
int main(){;}