设为首页 加入收藏

TOP

HDU-5031-Lines(DFS)
2015-07-20 17:38:59 来源: 作者: 【 】 浏览:2
Tags:HDU-5031-Lines DFS
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 
     using namespace std; int mp[55][55],ans,n,m,sum; map
     
      db;//用来根据斜率判重 void dfs(int dep,int remain) { if(dep>=ans) return; if(!remain) { ans=min(ans,dep); return; } int i,j,p,q,cnt; bool flag=0; for(i=0;i
      
       =0 && i+cnt*x
       
        =0 && j+cnt*y
        
         =0 && i+cnt*x
         
          =0 && j+cnt*y
          
           =0 && i-x
           
            =0 && j-y
            
             =0 && i+cnt*x
             
              =0 && j+cnt*y
              
               =0 && i+cnt*x
               
                =0 && j+cnt*y
                
                 

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇2进程之间的关系:进程组,会话,.. 下一篇6进程原语:wait()和waitpid()函数

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·数据库:推荐几款 Re (2025-12-25 12:17:11)
·如何最简单、通俗地 (2025-12-25 12:17:09)
·什么是Redis?为什么 (2025-12-25 12:17:06)
·对于一个想入坑Linux (2025-12-25 11:49:07)
·Linux 怎么读? (2025-12-25 11:49:04)