BZOJ1193 马步距离 (贪心)
恶心的题目= =
1 #include <cstdio> 2 #include <cmath> 3 #include <algorithm> 4 int f[5][5]={{0,3,2,3,2},{3,2,1,2,3},{2,1,4,3,2},{3,2,3,2,3},{2,3,2,3,4}}; 5 int main() 6 { 7 int a,b,c,d,x,y,ans=0; 8 scanf("%d%d%d%d",&a,&b,&c,&d); 9 x=abs(a-c); y=abs(b-d); 10 while ((x>4)||(y>4) ) 11 { 12 if (x>y) {x-=2; y-=1;} 13 else {x-=1; y-=2; } 14 x=abs(x); 15 y=abs(y); 16 ans++; 17 18 } 19 if ((x<=4)&&(y<=4)) {printf("%d",ans+f[x][y]); return 0;} 20 while ((x==1)&&(y>=4)) 21 { 22 x-=1; y-=2; ans++; 23 } 24 while ((y==1)&&(x>=4)) 25 { 26 x-=2; y-=1; ans++; 27 } 28 while ((x==0)&&(y>=4)) 29 { 30 y-=4; ans+=2; 31 } 32 while ((y==0)&&(x>=4)) 33 { 34 x-=2; ans+=2; 35 } 36 ans+=f[x][y]; 37 printf("%d",ans); 38 }