编程介的小学生 2019-02-06 14:49 采纳率: 20.5%
浏览 208

C语言动态链表分配方式计算这个问题的答,运用C语言编程的知识

Problem Description
Alexandra and her little brother are playing a game called "Clash of Submarines" (COS, for short). In this game, one can build so many(about 100,000) submarines, and detect and collect underwater treasures.
A submarine use radar to detect treasures. Alexandra's submarines are all face north. For each submarine, its radar can detect treasures between northwest and northeast. For example, the "S" is the submarine, and the "+" is a grid which the submarine can detect, and the "-" is which it cannot detect:
++++-
+++--

-S---

Note: the submarine can also detect the grid it occupies.
To simplify the problem, we build coordinate system on the map. X-axis goes from north to south, and Y-axis from west to east. We define the distance between two points (x1,y1) and (x2,y2) to be max(abs(x1-x2),abs(y1-y2)).
There is something special with the radar. Each submarine has a value D. The submarine can only detect a treasure, if D is a divisor of the distance between the submarine and the treasure. Don't forget any D is a divisor of 0.
Here comes the problem: Given the map of size N*M, and Q submarines' position and D, for each submarine please output the number of treasures it can detect.
Note: in this problem, we only detect treasures and won't collect them, so the submarines don't affect each other.

Input
There are multiple test cases (no more than 30).
For each case, the first line is three positive integers N, M and Q.
Next N lines is a map of size N*M. "X" means treasure and "." means no treasure.
Next Q lines, each line is the description of a submarine. There are three positive integers X, Y, D, which means its position is (X,Y), and its value is D.
1≤N,M≤1000.
1≤Q≤500,000.
1≤X≤N,1≤Y≤M.
1≤D≤1000.
Number of cases with max(N∗M,Q)>1,000 is no more than 3.
Huge data. Fast I/O may be needed.

Output
For each case, output Q lines, each line contains the number of treasures that the current submarine can detect.

Sample Input
4 5 3
.....
XXXXX
XXXXX
XXXXX
4 3 1
4 3 2
4 3 3
1 1 1
X
1 1 1

Sample Output
9
6
1
1

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 想问一下stata17中这段代码哪里有问题呀
    • ¥15 flink cdc无法实时同步mysql数据
    • ¥100 有人会搭建GPT-J-6B框架吗?有偿
    • ¥15 求差集那个函数有问题,有无佬可以解决
    • ¥15 【提问】基于Invest的水源涵养
    • ¥20 微信网友居然可以通过vx号找到我绑的手机号
    • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
    • ¥15 解riccati方程组
    • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
    • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决