编程介的小学生 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 微信公众号自制会员卡没有收款渠道啊
    • ¥15 stable diffusion
    • ¥100 Jenkins自动化部署—悬赏100元
    • ¥15 关于#python#的问题:求帮写python代码
    • ¥20 MATLAB画图图形出现上下震荡的线条
    • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
    • ¥15 perl MISA分析p3_in脚本出错
    • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
    • ¥15 ubuntu虚拟机打包apk错误
    • ¥199 rust编程架构设计的方案 有偿