您的位置:首页 > 其它

BZOJ1193 马步距离 (贪心)

2014-12-22 20:53 253 查看
恶心的题目= =

#include <cstdio>
#include <cmath>
#include <algorithm>
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}};
int main()
{
int a,b,c,d,x,y,ans=0;
scanf("%d%d%d%d",&a,&b,&c,&d);
x=abs(a-c); y=abs(b-d);
while ((x>4)||(y>4) )
{
if (x>y) {x-=2; y-=1;}
else {x-=1; y-=2; }
x=abs(x);
y=abs(y);
ans++;

}
if ((x<=4)&&(y<=4)) {printf("%d",ans+f[x][y]); return 0;}
while ((x==1)&&(y>=4))
{
x-=1; y-=2; ans++;
}
while ((y==1)&&(x>=4))
{
x-=2; y-=1; ans++;
}
while ((x==0)&&(y>=4))
{
y-=4; ans+=2;
}
while ((y==0)&&(x>=4))
{
x-=2; ans+=2;
}
ans+=f[x][y];
printf("%d",ans);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: