记录编号 107450 评测结果 AAAAAAAAAA
题目名称 [POJ1657] 棋盘上的距离 最终得分 100
用户昵称 GravatarHouJikan 是否通过 通过
代码语言 C++ 运行时间 0.004 s
提交时间 2014-06-25 21:55:52 内存使用 0.28 MiB
显示代码纯文本
  1. #include<iostream>
  2. #include <cstdio>
  3. #include <cmath>
  4. using namespace std;
  5. int main()
  6. {
  7. freopen("poj_1657.in","r",stdin);
  8. freopen("poj_1657.out","w",stdout);
  9. char ch[10];
  10. int fx,fy;
  11. int tx,ty;
  12. int cases;
  13. int a,b,c,k;
  14. cin>>cases;
  15. for(k=1;k<=cases;k++)
  16. {
  17. cin>>ch;
  18. fx=ch[0]-96;
  19. fy=ch[1]-'0';
  20. cin>>ch;
  21. tx=ch[0]-96;
  22. ty=ch[1]-'0';
  23. a=abs(fx-tx);
  24. b=abs(fy-ty);
  25. if (a<b) cout<<b<<' ';
  26. else cout<<a<<' ';
  27. if (fx==tx&&fy==ty) cout<<'0'<<' ';
  28. else
  29. if (fx==tx||fy==ty||fx-fy==tx-ty||fx+fy==tx+ty) cout<<'1'<<' ';
  30. else cout<<'2'<<' ';
  31. if (fx==tx&&fy==ty) cout<<'0'<<' ';
  32. else
  33. if (fx==tx||fy==ty) cout<<'1'<<' ';
  34. else cout<<"2 ";
  35. int k=fx+fy-tx-ty;
  36. if (k<0)k=-k;
  37. if (k%2==1) cout<<"Inf"<<endl;
  38. else if(fx==tx&&fy==ty) cout<<'0'<<endl;
  39. else if(fx-fy==tx-ty||fx+fy==tx+ty) cout<<'1'<<endl;
  40. else cout<<"2"<<endl;
  41. }
  42. }