编程介的小学生 2017-03-21 14:39 采纳率: 0.2%
浏览 996
已采纳

Link Link Look

A single player game is played on a grid chessboard with some colored beads on. In each round, the player can click on two grids of the chessboard. If the two grids both have beads of the same color, and a line with no more than two turns could be drawn to connect the two beads, the two beads will both disappear from the chessboard. Note that the line must not pass through any other beads.

Figure 1: Valid clicks that will erase the two beads
Given the information of a chessboard and the player's clicks in each round, you are required to calculate how many beads will disappear.

Input
The input consists of several test cases. The first line of each case contains two numbers N and M (1 <= N, M <= 100), indicating the dimensions of the chessboard. Then N lines follow, each represents a row of the chessboard. The positive numbers represent different colors of beads, and zero represents an empty grid. Then there is a positive number T followed by T lines of input which describe the clicks of all T rounds. Each line contains four numbers x1, y1, x2, y2 which are the positions (x1, y1) and (x2, y2) of the two clicks on the chessboard (the north-west corner is at (1, 1)).

Output

For each case, print in one line the number of beads disappeared.

Sample Input

3 4
1 1 2 2
3 3 4 4
2 2 1 1
6
1 1 1 2
1 3 1 4
2 1 2 2
2 3 2 4
3 1 3 2
3 3 3 4

3 4
1 2 1 2
3 4 3 4
2 1 2 1
6
1 1 1 2
1 3 1 4
2 1 2 2
2 3 2 4
3 1 3 2
3 3 3 4

3 4
1 2 1 2
1 1 2 2
2 2 1 1
3
2 3 2 4
2 2 3 3
3 2 1 4

2 3
0 0 0
0 0 0
2
1 1 1 1
1 1 1 2

0 0

Sample Output

12
0
6
0

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-03-29 15:06
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Android STD快速启动
  • ¥15 如何使用simulink建立一个永磁同步直线电机模型?
  • ¥30 天体光谱图的的绘制并得到星表
  • ¥15 PointNet++的onnx模型只能使用一次
  • ¥20 西南科技大学数字信号处理
  • ¥15 有两个非常“自以为是”烦人的问题急期待大家解决!
  • ¥30 STM32 INMP441无法读取数据
  • ¥15 R语言绘制密度图,一个密度曲线内fill不同颜色如何实现
  • ¥100 求汇川机器人IRCB300控制器和示教器同版本升级固件文件升级包
  • ¥15 用visualstudio2022创建vue项目后无法启动