Metal Steak

Hard to eat

  C++博客 :: 首页 :: 联系 :: 聚合  :: 管理
  0 Posts :: 79 Stories :: 0 Comments :: 0 Trackbacks

公告

aaaaaaaaaaaa

常用链接

留言簿(1)

我参与的团队

搜索

  •  

最新评论

#include <iostream>
using namespace std;

int cnt = 0;
const int delta[4][2= {{1-2}, {2-1}, {21}, {12}};

struct
point
{
    
int
    x, y;
    point()
    {
        x 
= y = 0;
    }
}p[
1001], target;

ostream
& operator << (ostream& out, point ppp)
{
    
out << "(" << ppp.x << "," << ppp.y << ")";
    
return out;
}

void
__read__()
{
    cin 
>> target.x >> target.y;
}

void
__outp__()
{
    point pppp;
    cout 
<< pppp;
    
for(int i = 1; i <= cnt; i++)
        cout 
<< p[i];
    cout 
<< endl;
}

void
__dfs__(point pp)
{
    
if(pp.x == target.x
    
&& pp.y == target.y)
    {
        __outp__();
        
return;
    }

    
for(int i = 0; i <= 3; i++)
    {
        point pt 
= pp;
        pt.x 
+= delta[i][0];
        pt.y 
+= delta[i][1];
        
if(pt.x <= target.x && pt.x >= 0
        
&& pt.y <= target.y && pt.y >= 0)
        {
            p[
++cnt] = pt;
            __dfs__(pt);
            cnt
--;
        }
    }
}

int
main()
{
    point source;
    __read__();
    __dfs__(source);

    
return 0;
}

posted on 2009-09-15 21:22 mad4alcohol 阅读(205) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航:   博客园   博客园最新博文   博问   管理