NOJ1127——[1127] Kill the Zombies

  • 问题描述
  • Magical girl just rescued the princess from the zombie Castle,so The Zombie King was very angry and sent most of the zombies to pursue the magical girl.As a result, magical girl consumed a large amount of capacity so that she can not continue to fight,so she set some traps to stop the zombies'advance.If both the trap and zombie were at the same lattice,the trap will be swallowed by zombie,then the zombie and the trap will disappear together.The trap was triggerred from left to right one by one in the map(if there were at least two traps on the same column,in the above will be the first to launch).After the launch,the trap will produce flame,it will spread for four directions ,whatever it will meet,the flame will continue to go forward out of map(left is first,then is up,after is right,last is down).The trap will disappear after the launch.If the flame hit the another trap,the trap which was hit will disappear;if the flame hit the zombie,just before it happened,the zombie will move a lattice to dodge the flame(up is first than down,left is first than right,the zombie can not move out of map),if there was a zombie has occupied the lattice,that zombie can not move and he will move to another direction,if there was also a zombie has occupied contrary direction of the lattice,the zombie will fall back one lattice(if there was a zombie in this zombie's back,he will eat the zombie behind)and this zombie will also be burned to death.

    ps : for each zombie, he just move one step.
  • 输入
  • The input data include several cases, input until EOF.
    In each case,there will be two integers m and n(2<m,n<10)stands map at first line,m is the number of lines,n is the number of columns.
    Then it will follow one integer w means the number of zombies,then it follows w lines,each line include two integers x and y means the coordinate of zombie(x is the coordinate of line,y is the coordinate of column).
    Then it will follow one integer t means the number of traps,then it follows t lines,each line include two integers x and y means the coordinate of zombie(x is the coordinate of line,y is the coordinate of column).
  • 输出
  • For each case, you should output the survival of zombies.
  • 样例输入
  • 4 5
    6
    0 0
    1 0
    1 2
    2 1
    2 2
    3 2
    2
    1 1
    2 3
  • 样例输出
  • 5
  • 提示
  • 来源
  • hungar
XX出的一道模拟题,一开始始终WA,后来发现方向搞错了,改回来就AC了,这题只要能把情况都列出来,就不难了。

//NOJ 1127
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<iterator>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<list>
#define pi acos(-1);

using namespace std;

int mat[14][14];//地图,0表示无,1表示有僵尸,2表示有陷阱

int cnt, n, m, w, ans;//w是僵尸个数,cnt是陷阱个数,ans是可存活的僵尸

int dir[4][2] = {{0, -1}, {-1, 0}, {0,1}, {1, 0}};

inline bool is_legal(int x, int y)
{
return (x >= 0 && x < n && y >=0 && y < m);
}

void init()
{
memset(mat, 0, sizeof(mat));
scanf("%d", &w);
ans = w;
int x, y;
for(int i = 0; i < w; i++)
{
scanf("%d%d", &x, &y);
mat[x][y] = 1;
}
scanf("%d", &cnt);
for(int i = 0; i < cnt; i++)
{
scanf("%d%d", &x, &y);
if(mat[x][y] == 1)
{
mat[x][y] = 0;
ans--;
}
else
mat[x][y] = 2;
}
}

void trap_launch(int x, int y)//传入陷阱的坐标
{
for(int i = 0; i < 4; i++)
{
int newx = x + dir[i][0];
int newy = y + dir[i][1];
while(is_legal(newx, newy))//坐标合法
{
if(mat[newx][newy] == 2)//火焰传递时碰到其他陷阱
{
mat[newx][newy] = 0;
}
else if(mat[newx][newy] == 1)//碰到僵尸,僵尸的行动要判断
{
if(i == 0)//火焰向左过来
{
if(newx >= 1 && mat[newx - 1][newy] == 0)//向上
{
mat[newx][newy] = 0;
mat[newx - 1][newy] = 1;
}
else if(newx + 1 < n && mat[newx + 1][newy] == 0)
{
mat[newx][newy] = 0;
mat[newx + 1][newy] = 1;
}
else
{
ans--;
mat[newx][newy]=0;
if(newy - 1 >= 0 && mat[newx][newy - 1] == 1)
{
ans--;
mat[newx][newy - 1] = 0;
}
}
}
else if(i == 2)
{
if(newx >= 1 && mat[newx - 1][newy] == 0)//向上
{
mat[newx][newy] = 0;
mat[newx - 1][newy] = 1;
}
else if(newx >= 1 && mat[newx - 1][newy] == 2)
{
ans--;
mat[newx][newy] = 0;
mat[newx - 1][newy] = 0;
}
else if(newx + 1 < n && mat[newx + 1][newy] == 0)
{
mat[newx][newy] = 0;
mat[newx + 1][newy] = 1;
}
else if(newx + 1 < n && mat[newx + 1][newy] == 2)
{
ans--;
mat[newx][newy] = 0;
mat[newx + 1][newy] = 0;
}
else
{
ans--;
mat[newx][newy]=0;
if(newy + 1 < m && mat[newx][newy + 1] == 1)
{
ans--;
mat[newx][newy + 1] = 0;
}
else if(newy + 1 < m && mat[newx][newy + 1] == 2)
mat[newx][newy + 1]=0;
}
}
else if(i == 1)//火焰向上
{
if(newy - 1 >= 0 && mat[newx][newy - 1] == 0)
{
mat[newx][newy] = 0;
mat[newx][newy - 1] = 1;
}
else if(newy + 1 < m && mat[newx][newy + 1] == 0)
{
mat[newx][newy] = 0;
mat[newx][newy + 1] = 1;
}
else if(newy + 1 < m && mat[newx][newy + 1] == 2)
{
ans--;
mat[newx][newy] = 0;
mat[newx][newy + 1] = 0;
}
else
{
ans--;
mat[newx][newy]=0;
if(newx >= 1&& mat[newx - 1][newy] == 1)
{
ans--;
mat[newx - 1][newy] = 0;
}
}
}
else if(i == 3)
{
if(newy >= 1 && mat[newx][newy - 1] == 0)
{
mat[newx][newy] = 0;
mat[newx][newy - 1] = 1;
}
else if(newy + 1 < m && mat[newx][newy + 1] == 0)
{
mat[newx][newy] = 0;
mat[newx][newy + 1] = 1;
}
else if(newy + 1 < m && mat[newx][newy + 1] == 2)
{
ans--;
mat[newx][newy] = 0;
mat[newx][newy + 1] = 0;
}
else
{
ans--;
mat[newx][newy] = 0;
if(newx + 1 < n && mat[newx + 1][newy] == 1)
{
ans--;
mat[newx + 1][newy] = 0;
}
else if(newx + 1 < n && mat[newx + 1][newy] == 2)
mat[newx + 1][newy] = 0;
}
}
}
newx += dir[i][0];
newy += dir[i][1];
}
}
}

void judge()
{
for(int j = 0; j < m; j++)
{
for (int i = 0; i < n; i++)
{
if(mat[i][j] == 2)
{
trap_launch(i, j);
mat[i][j] = 0;
}
}
}
}

int main()
{
while(~scanf("%d%d",&n, &m))
{
init();
judge();
printf("%d\n", ans);
}
return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值