Problem Description You play a game with your friend. He draws several lines on the paper with n×m square grids (see the left figure). After that, he writes down the number of lines passing through every integer coordinate in a matrix (see the right figure).
The number of lines passing though coordinate (i,j) is written in cell (i,j) in the right figure.(i,j both start from 0).
You are given the matrix written by your friend. You need to figure out the possible minimal number of lines your friend drew on the paper.
Input The first line of the input contains an integer T indicating the number of test cases( 0 < T <= 10).
FZ??http://www.2cto.com/kf/ware/vc/" target="_blank" class="keylink">vciBlYWNoIHRlc3QgY2FzZSwgdGhlIGZpcnN0IGxpbmUgY29udGFpbnMgdHdvIGludGVnZXJzIG4sIG0gKDEgodwgbiwgbSCh3CA1MCkgcmVwcmVzZW50aW5nIHRoZSBzaXplIG9mIHRoZSBncmlkcyBvbiB0aGUgcGFwZXIuIFRoZSBmb2xsb3dpbmcgKG4mIzQzOzEpIKHBIChtJiM0MzsxKSBudW1iZXJzIGlzIHdoYXQgeW91ciBmcmllbmQgd3JpdGVzLiBJdCBpcyBndWFyYW50ZWVkIHRoYXQgdGhlIG51bWJlciBvZiBsaW5lcyB5b3VyIGZyaWVuZCBkcmF3cyBkb2VzIG5vdAogZXhjZWVkIDE0LiBFYWNoIGxpbmUgcGFzc2VzIHRocm91Z2ggaW50ZWdlciBjb29yZGluYXRlcyBhdCBsZWFzdCB0aHJlZSB0aW1lcy4KCiAKPGJyPgoKT3V0cHV0CgpGb3IgZWFjaCB0ZXN0IGNhc2UsIHlvdSBuZWVkIHRvIG91dHB1dCB0aGUgbWluaW1hbCBudW1iZXIgb2YgbGluZXMgeW91ciBmcmllbmQgZHJldyBvbiB0aGUgcGFwZXIgaW4gYSBzaW5nbGUgbGluZS4KCiAKPGJyPgoKU2FtcGxlIElucHV0Cgo8cHJlIGNsYXNzPQ=="brush:java;">1 5 4 0 1 0 0 1 0 1 0 1 0 2 1 1 0 0 0 3 1 0 0 1 1 1 0 1 0 1 0 1 0
Sample Output
4
Source 2014 ACM/ICPC Asia Regional Guangzhou Online
思路:枚举经过当前点的所有可能直线即可。详见代码。
#include
#include
#include