您的位置:首页 > 其它

hdu 1577【WisKey的眼神】

2012-05-20 21:44 295 查看
代码如下:

#include <cstdio>
#include <cmath>
#include <algorithm>

void solve();
int  L,sx,sy,px,py;

int main()
{
while(scanf("%d",&L),L)
{
scanf("%d%d%d%d",&sx,&sy,&px,&py);

if(py > L || px > L || py < -L || px < -L)
{
printf("Out Of Range\n");
continue;
}

solve();
}

return 0;
}

void solve()
{
int a = px - sx;
int b = py - sy;

if(a == 0)
{
if(abs(b) <= 1)
{
printf("Yes\n");
}
else
{
printf("No\n");
}

return;
}

if(b == 0)
{
if(abs(a) <= 1)
{
printf("Yes\n");
}
else
{
printf("No\n");
}

return;
}

if(abs(a) == 1 && abs(b) == 1)
{
printf("Yes\n");
return;
}

int minn = std::min(sx,px);
int maxm = std::max(sx,px);

for(int i = minn +  1;i < maxm;i ++)
{
int temp = b * i + a * sy - b * sx;
if(temp % a == 0)
{
if(temp / a < std::max(sy,py) && temp / a > std::min(sy,py))
{
printf("No\n");
return;
}
}
}

printf("Yes\n");
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: