ZOJ 1860 || Dog & Gopher(空行区分case

难过都是莫名其妙的几何水题。要刷到什么时候我才能刷到高难度。

比较一下逃脱点到田鼠和狗的距离就好了。

注意一下是以空行来区分每个case。

#include<iostream>
#include<cstdio>
#include<sstream>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
struct point{double x,y;int id;};
point hole,ans,dog,gopher;
const double eps = 1e-6;
void dist(point hole,double &todog,double &togop)
{
    todog = sqrt ( (dog.x - hole.x)*(dog.x - hole.x)+
                  (dog.y-hole.y)*(dog.y-hole.y) );
    togop = sqrt ( (gopher.x - hole.x)*(gopher.x - hole.x)+
                  (gopher.y-hole.y)*(gopher.y-hole.y) );
}
char str[100];
int main()
{
    //freopen("in.txt","r",stdin);
    while( ~scanf("%lf %lf %lf %lf\n",&gopher.x,&gopher.y,&dog.x,&dog.y))
    {
        int flag  = 1;
        double todog,togop;
        while(gets(str))
        {
            if( strlen(str)==0)break;
            sscanf(str,"%lf%lf",&hole.x,&hole.y);
            dist(hole,todog,togop);
            if( flag && togop < todog *0.5)
            {
                 printf("The gopher can escape through the hole at (%.3lf,%.3lf).\n",
                       hole.x,hole.y);
                flag = 0;
            }
        }
        if( flag )
            puts("The gopher cannot escape.");
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值