编程介的小学生 2019-02-03 11:05 采纳率: 20.5%
浏览 323

方向编号,然后计算网格路径的问题,用到搜索算法,怎么利用C语言实现

Problem Description
There are N cowboys in the arena, tagged with 1 to N. The arena can be considered as an N * N grid.

At first, every cowboy is standing on a grid point (lower left point is (1,1) and upper right is (N,N)).

Then the god named Matt will give M orders to the cowboys. All orders look like this: (i,dir,distance) which means the i-th cowboy moving distance step in dir direction.

And dir will be:

● '1' for East ((x,y)->(x + 1, y) for one step)
● '2' for North ((x,y)->(x, y + 1) for one step)
● '3' for West ((x,y)->(x - 1, y) for one step)
● '4' for South ((x,y)->(x, y - 1) for one step)

Since the cowboys can't get out of the arena, they will stop moving if they reach the boundary of the arena.

The cowboys are so aggressive that they always want to duel, but only the one that is moving can duel another cowboy. If a cowboy A is given an order, he will first turn his direction to the moving direction.

Then A will look at both his left hand direction and right hand direction, and the point now he is standing. If someone B is insight, A and B will have a duel, and the one with a smaller tag number will be the winner and loser will leave the arena, and A will stop moving immediately.

If no one is insight, A will go one step and start looking again. The process will stop if someone is insight, or A has moved for 'distance' steps and no one is insight.

Since the Cowboys' eyesight is not so good, they can only see someone if the distance between them is no more than D.

Since all cowboys are confident, if there are more than one cowboy insight, they will choose to duel the one with the smallest tag number.

Furthermore, Matt will give an order only if the previous cowboy has stopped. It's possible for more than one cowboy on one point. Nothing will happen if Matt gives an order to a cowboy that has left the arean.

Now, given the initial location of the cowboys and the orders, we want to know the final situation of the arena.

Input
The first line of the input contains an integer T, denoting the number of testcases. Then T test cases follow.

For each test case, the first line contains three integers:N,M,D(1<=N<= 50000,M<=50000,0<=D).

In the following N lines, the i-th line contains two integers:X,Y (1<=X, Y <=N) indicating the initial location of the i-th cowboy.

In the following M lines, the i-th line contains three integers:I,Dir,Dis(1<=I <=N, 1<=Dir<=4, 0<=Dis<=N) indicating the i-th order given by Matt.

All the numbers appears in the input will not exceed 10^9.

Output
For each test case, first output one line "Case #x:", where x is the case number (starting from 1).

Then for each cowboy that has not left the arena, output his tag number and final location in one line(Output in tag number order).

Sample Input
1
5 2 1
1 1
5 5
1 5
5 1
3 3
5 4 1
1 1 2

Sample Output
Case #1:
1 3 1
2 5 5
3 1 5
4 5 1

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 matlab有限元法求解梁带有若干弹簧质量系统的固有频率
    • ¥15 找一个网络防御专家,外包的
    • ¥100 能不能让两张不同的图片md5值一样,(有尝)
    • ¥15 informer代码训练自己的数据集,改参数怎么改
    • ¥15 请看一下,学校实验要求,我需要具体代码
    • ¥50 pc微信3.6.0.18不能登陆 有偿解决问题
    • ¥20 MATLAB绘制两隐函数曲面的交线
    • ¥15 求TYPCE母转母转接头24PIN线路板图
    • ¥100 国外网络搭建,有偿交流
    • ¥15 高价求中通快递查询接口