From c661fc242e0ab1962726b081ae8cd1cba73e1f97 Mon Sep 17 00:00:00 2001 From: Kirito <1362050620@qq.com> Date: Fri, 19 Aug 2016 10:20:50 +0800 Subject: [PATCH] Create 1178_mythit.cpp From http://www.cppblog.com/mythit/archive/2009/07/02/89123.html --- POJ/1178_mythit.cpp | 80 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 POJ/1178_mythit.cpp diff --git a/POJ/1178_mythit.cpp b/POJ/1178_mythit.cpp new file mode 100644 index 0000000..e79682c --- /dev/null +++ b/POJ/1178_mythit.cpp @@ -0,0 +1,80 @@ +#include +#include +#include +#include +using namespace std; + +const int inf = 100000; +char str[150]; +int k[64],king[64][64],knight[64][64]; +int move1[8][2]={-1,-1,-1,0,-1,1,0,1,1,1,1,0,1,-1,0,-1}; +int move2[8][2]={-1,-2,-2,-1,-2,1,-1,2,1,2,2,1,2,-1,1,-2}; + +void init(){ + int i,j,x,y,tx,ty; + for(i=0;i<64;i++) + for(j=0;j<64;j++) + if(i==j) king[i][j]=knight[i][j]=0; + else king[i][j]=knight[i][j]=inf; + for(i=0;i<64;i++){ + x=i/8,y=i%8; + for(j=0;j<8;j++){ + tx=x+move1[j][0],ty=y+move1[j][1]; + if(tx>=0 && ty>=0 && tx<8 && ty<8) + king[i][8*tx+ty]=1; + } + } + for(i=0;i<64;i++){ + x=i/8,y=i%8; + for(j=0;j<8;j++){ + tx=x+move2[j][0],ty=y+move2[j][1]; + if(tx>=0 && ty>=0 && tx<8 && ty<8) + knight[i][8*tx+ty]=1; + } + } +} +void floyd1(){ + int i,j,k; + for(k=0;k<64;k++) + for(i=0;i<64;i++) + for(j=0;j<64;j++) + if(king[i][k]+king[k][j]