zoukankan      html  css  js  c++  java
  • [YTU]_2613( 距离产生美)

    题目描述

    小明和静静是大学同学,毕业后要去两个不同的城市工作。小明要静静做他的女朋友,静静说,如果他们的工作单位之间的距离在某个范围之内的话,就考虑小明的要求。

    C++代码如下,只需提交空缺部分

    #include <iostream>
    #include <math.h>
    #include <iomanip>
    using namespace std;
    /***********************/

              填空部分

    /***********************/

    double Distance(Point &p1,Point &p2)
    {
        double d;
        d=sqrt((p1.x-p2.x)*1.0*(p1.x-p2.x)+(p1.y-p2.y)*1.0*(p1.y-p2.y));
        return d;
    }
    int main()
    {
        double d;
        Point p1,p2;
        p1.input();
        p2.input();
        d=Distance(p1,p2);
        int r1,r2;
        cin>>r1>>r2;
        if(d>=r1&&d<=r2)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
        return 0;
    }

    输入

    输入有三行,所有数据均为正整数
    第一行为小明单位的坐标 x1 y1
    第二行为静静单位的坐标 x2 y2
    第三行为静静要求的距离范围 r1 r2

    输出

    如果静静答应做小明的女朋友输出 "Yes",否则输出"No"。

    样例输入

    10 10
    20 20
    12 15

    样例输出

    Yes
    #include <iostream>
    #include <math.h>
    #include <iomanip>
    using namespace std;
    class Point
    {
    public:
        void input();
        int x;
        int y;
    };
    void Point::input()
    {
        cin>>x>>y;
    }
    double Distance(Point &p1,Point &p2)
    {
        double d;
        d=sqrt((p1.x-p2.x)*1.0*(p1.x-p2.x)+(p1.y-p2.y)*1.0*(p1.y-p2.y));
        return d;
    }
    int main()
    {
        double d;
        Point p1,p2;
        p1.input();
        p2.input();
        d=Distance(p1,p2);
        int r1,r2;
        cin>>r1>>r2;
        if(d>=r1&&d<=r2)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
        return 0;
    }
    

  • 相关阅读:
    Qt5 webview加载本地网页
    pwiz, a model generator
    编译python3
    [转]Centos配置国内yum源
    ubuntu下apt-get update出现hash校验和错误
    《LINUX程序设计 第四版》 阅读笔记:(一)
    [转]https方式使用git保存密码的方式
    用python产生一个好的秘钥
    Ubuntu关闭图形界面
    Numpy中的矩阵计算
  • 原文地址:https://www.cnblogs.com/sxy201658506207/p/7586351.html
Copyright © 2011-2022 走看看