Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1546765
  • 博文数量: 327
  • 博客积分: 10000
  • 博客等级: 上将
  • 技术积分: 3556
  • 用 户 组: 普通用户
  • 注册时间: 2005-04-05 21:28
个人简介

东黑布衣,流浪幽燕。 真诚善良,值得信赖。

文章分类

全部博文(327)

我的朋友

分类: BSD

2005-07-29 22:02:09


  1. #include <stdio.h>
  2. #include <string.h>
  3. int a[5][4];
  4. int jump[8][2]={{-1,-2},{-1,2},{-2,1},{-2,-1},
  5.                 {2,1},{2,-1},{1,2},{1,-2}};
  6. int chess[6][5];
  7. int sx,sy,total;

  8. int find_w(int p1,int p2)
  9. {
  10.    int pi,pj,i;
  11.    for(i=0;i<8;i++)
  12.    {
  13.       pi=p1+jump[i][0]; /* x axis: column */
  14.       pj=p2+jump[i][1]; /* y axis: row */
  15.       if(pi>=1 && pj>=1 && pi<5 && pj<6 && chess[pj][pi]==0)
  16.       {
  17.          chess[pj][pi]=1;
  18.          find_w(pi,pj);
  19.          chess[pj][pi]=0;
  20.       }
  21.       else if(pi==sx && pj==sy)
  22.          total+=1;
  23.    }
  24.    return 0;
  25. }

  26. int main()
  27. {
  28.    int T;
  29.    int i;
  30.    freopen("0601i.txt","r",stdin);
  31.    scanf("%d",&T);
  32.    for(i=1;i<=T;i++)
  33.    {
  34.       memset(chess,0,sizeof(chess));
  35.       scanf("%d %d", &sx,&sy);
  36.       if(sx<5 && sx>0 && sy<6 && sy>0)
  37.       {
  38.          chess[sy][sx]=1;
  39.          total=0;
  40.          find_w(sx,sy);
  41.          printf("total num is %d\n", total);
  42.       }
  43.       else
  44.          printf("ERROR input\n");
  45.    }
  46.    fclose(stdin);
  47.    return 0;
  48. }
  49. /* input
  50. 5
  51. 2 2
  52. 1 1
  53. 4 6
  54. 1 3
  55. 2 3
  56. */


阅读(2591) | 评论(1) | 转发(0) |
0

上一篇:A Forever Friend

下一篇:Life is full of choices

给主人留下些什么吧!~~