比赛 |
2008haoi模拟训练2 |
评测结果 |
ATTTTTTTTT |
题目名称 |
坦克游戏 |
最终得分 |
10 |
用户昵称 |
zqzas |
运行时间 |
0.000 s |
代码语言 |
C++ |
内存使用 |
0.00 MiB |
提交时间 |
2008-04-23 11:26:27 |
显示代码纯文本
#include <stdio.h>
#define maxn 510
int n,m,r,t,now,total,flag2,data[maxn][maxn];
long ans;
FILE *f1,*f2;
int attack(int x,int y)
{
int i,j,max_x,max_y,left,right,up,down,flag;
left=y-r;
if (left<0)
left=0;
right=y+r;
if (right>=m)
right=m-1;
up=x-r;
if (up<0)
up=0;
down=x+r;
if (down>=n)
down=n-1;
max_x=max_y=500;
data[max_x][max_y]=0;
flag=0;
for (i=up;i<=down;i++)
for (j=left;j<=right;j++)
{
if (data[i][j]>data[max_x][max_y])
{
max_x=i;
max_y=j;
flag=1;
}
}
if (flag==0)
return 0;
return max_x*m+max_y;
}
void search(int x,int y,int time,int point)
{
int zan,a,b;
if (time>=t)
{
if (point>ans)
ans=point;
if (now>=total)
flag2=1;
return;
}
if (flag2)
return;
zan=attack(x,y);
if (zan!=0)
{
a=zan/m;
b=zan%m;
zan=data[a][b];
data[a][b]=0;
now++;
search(x,y,time+1,point+zan);
data[a][b]=zan;
now--;
}
if (x+1<n)
search(x+1,y,time+1,point);
if (y+1<m)
search(x,y+1,time+1,point);
}
void run(void)
{
flag2=0;
search(0,0,0,0);
}
void ini(void)
{
int i,j;
fscanf(f1,"%d%d%d%d",&n,&m,&r,&t);
for (i=0;i<n;i++)
for (j=0;j<m;j++)
{
fscanf(f1,"%d",&data[i][j]);
if (data[i][j]!=0)
total++;
}
}
int main(void)
{
f1=fopen("gametk.in","r");
f2=fopen("gametk.out","w");
ini();
run();
fprintf(f2,"%ld\n",ans);
fclose(f1);fclose(f2);
return 0;
}