编程介的小学生 2018-12-04 14:17 采纳率: 20.5%
浏览 377
已采纳

一个路径的统计问题,作不出来,请大家看看怎么编程实现

Problem Description
JRY is so rich that he creates an m demensional space and n sight spots inside. Because of special technical problem, all the coordinates are integers between [0,2]. The roads in this space are all parallel to the axis, so the distance between two sight spots is their Manhattan distance. More specifically, if the coordinate of one sight spot is (x1,x2,…,xm), and that of another sight spot is (y1,y2,…,ym), then their distance is ∑mi=1|xi−yi|. JRY wants to establish some bus routes between two sight spots, so he needs to do some research first. For you, the problem is to find the total number of pairs (x,y) for each k, that the distance between (x,y) is k. Please be aware: 1. (x,x) does not count; 2. (x,y) and (y,x) are identical, so that it is only one pair; 3. different sight spots may have same coordinates.

Input
The first line of the input is a single integer T (T=11), indicating the number of testcases.

For each testcase, the first line contains two integers n and m. Each of the following n lines contains one string of length m, which consists three types of characters 0,1,2, and the j-th character of the i-th string means the j-th coordinate of the i-th spot. It is guaranteed that the m of the i-th testcase is i, and for all testcases ∑n≤300000.

Output
For each testcase, print 2m+1 lines. The single number in the i-th line of the output indicates the number of pairs of sight spots with distance i−1

Sample Input
2
2 1
0
1
6 2
00
01
10
11
02
00

Sample Output
0
1
0
1
7
6
1
0

  • 写回答

1条回答 默认 最新

  • threenewbee 2019-03-28 10:43
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)