编程介的小学生 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 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程