zoukankan      html  css  js  c++  java
  • rwkj 1284 ------nyist 101 两点距离


    101


    两点距离
    时间限制:3000 ms | 内存限制:65535 KB
    难度:1
    描述
    输入两点坐标(X1,Y1),(X2,Y2)(0<=x1,x2,y1,y2<=1000),计算并输出两点间的距离。
    输入
    第一行输入一个整数n(0<n<=1000),表示有n组测试数据;
    随后每组占一行,由4个实数组成,分别表示x1,y1,x2,y2,数据之间用空格隔开。
    输出
    对于每组输入数据,输出一行,结果保留两位小数。
    样例输入
    2
    0 0 0 1
    0 1 1 0样例输出
    1.00
    1.41


    #include<math.h>
    #include<stdio.h>
    main()
    { int N ;
    float a,b,c,d;
    double s;

    scanf("%d ",&N);
    while(N--)
    {
    scanf("%f %f %f %f",&a,&b,&c,&d);
    s=sqrt((a-c)*(a-c)+(b-d)*(b-d));


    printf("%.2f ",s);
    }
    }


    #include<stdio.h>
    #include<math.h>
    int main()
    {
    int n;
    scanf("%d",&n);
    while(n--)
    {
    float x1,y1,x2,y2,a;
    scanf("%f %f %f %f",&x1,&y1,&x2,&y2);
    a=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
    printf("%.2f ",a);
    }
    return 0;
    }


    #include<stdio.h>
    #include<iostream>
    #include<math.h>
    using namespace std;
    int main()
    {
    int n;
    double d,x1,y1,x2,y2;
    cin>>n;
    while(n--)
    {
    cin>>x1>>y1>>x2>>y2;
    d=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
    printf("%.2f ",d);
    }
    return 0;
    }


    #include <stdio.h>
    #include <math.h>
    int main ( )
    {
    int n,i;
    float x1,x2,y1,y2,m,k;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
    scanf ("%f %f %f %f", &x1,&y1,&x2,&y2); //scanf ("%f %f %f %f ", &x1,&y1,&x2,&y2); ERROR
    m=((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
    k=sqrt(m);
    printf("%.2f ",k);
    }
    return 0;
    }


    #include<iostream>
    #include <iomanip>
    #include<math.h>
    using namespace std;
    int main()
    {
    int n;
    double m,j,x1,y1,x2,y2;
    cin>>n;
    while(n--)
    {
    cin>>x1>>y1>>x2>>y2;
    m=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
    j=sqrt(m);
    cout.setf(ios::fixed);
    cout<<setprecision(2)<<j<<endl;
    }
    return 0;
    }


    #include<iostream>
    #include<iomanip>
    #include<cmath>
    using namespace std;
    int main()
    {
    int n;
    double x1,x2,y1,y2;
    cin>>n;
    while(n--)
    {
    cin>>x1>>y1>>x2>>y2;
    cout<<setprecision(2)<<setiosflags(ios::fixed)<<sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))<<endl;
    }
    return 0;
    }


    #include <iostream>
    #include <cmath>
    #include <iomanip>
    using namespace std;
    int main()
    {
    int m;
    cin>>m;
    while(m--)
    {
    double x1,y1,x2,y2;
    cin>>x1>>y1>>x2>>y2;
    cout<<fixed<<setprecision(2)<<sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))<<endl;
    }
    return 0;
    }


    #include <stdio.h>
    #include <math.h>
    #include <iostream>
    using namespace std;

    int main()
    {
    double round,x1,y1,x2,y2,dis;
    cin>>round;
    while (round--)
    {
    cin>>x1>>y1>>x2>>y2;
    dis=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
    printf("%.2f ",dis);
    }
    return 0;
    }

    #include<stdio.h>
    #include<math.h>
    float fun(float x1,float x2,float y1,float y2){
    float s1,s2,s3;
    s1=(x1-x2)*(x1-x2);
    s2=(y1-y2)*(y1-y2);
    s3=sqrt(s1+s2);
    return s3;
    }
    int main(){
    float x1,x2,y1,y2;
    int n;
    float m;
    scanf("%d",&n);
    while(n--){
    scanf("%f %f %f %f",&x1,&x2,&y1,&y2);
    m=fun(x1,x2,y1,y2);
    printf("%.2f ",m);
    }
    return 0;
    }

    *********************************

    #include<iostream>
    #include<cmath>
    #include<iomanip>
    using namespace std;
    double power(double x)
    {
    double f=1.0;
    f=x*x;
    return (f);

    }
    int main()
    {
    double power(double x);
    double x[2],y[2],n;
    int m,i;
    cin>>m;
    while(m--)
    {
    cin>>x[0]>>y[0]>>x[1]>>y[1];
    n=0.0;
    i=n=sqrt(power((x[0]-y[0]))+power((x[1]-y[1])));
    if(n==i)
    cout<<n<<".00"<<endl;
    else
    cout<<setprecision(3)<<n<<endl;
    }
    return 0;
    }


    ************************************


    #include<stdio.h>
    #include<math.h>
    int main(void)
    {
    double n,x1,y1,x2,y2,ans;
    scanf("%d",&n);
    while(n--)
    {
    scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
    ans=sqrt(pow(fabs(x1-x2),2)+pow(fabs(y1-y2),2));
    printf("%.2f ",ans);
    }
    return 0;
    }

    #include <iostream>
    #include <cmath>
    #include <iomanip>
    using namespace std;
    int main()
    {
    double n,a[4],e,b,d;
    cin>>n;
    while(n--)
    {
    for(int i=0;i<4;i++)
    cin>>a[i];
    e=(a[0]-a[2])*(a[0]-a[2]);
    b=(a[1]-a[3])*(a[1]-a[3]);
    d=sqrt(e+b);
    cout<<setiosflags(ios::fixed)<<setprecision(2)<<d<<endl;
    }
    return 0;
    } //有没学C++的?

    #include<stdio.h>
    #include<math.h>
    int main()
    {
    int n,i;
    float a[100],b[100],x1,x2,y1,y2;
    scanf("%d ",&n);
    for(i=0;i<n;i++)
    {scanf("%f %f %f %f",&x1,&y1,&x2,&y2);
    a[i]=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
    }
    for(i=0;i<n;i++)printf("%.2f ",a[i]);
    }

    #include<stdio.h>
    #include<math.h>
    main()
    {
    int x1[1000]={0},x2[1000]={0},y1[1000]={0},y2[1000]={0},n,t,i;
    float s[1000]={0};
    scanf("%d",&n);
    for(i=0;i<n;i++)
    scanf("%d %d %d %d",&x1[i],&y1[i],&x2[i],&y2[i]);
    for(i=0;i<n;i++)
    {
    t=x2[i]*x2[i]-x1[i]*x1[i]+y2[i]*y2[i]-y1[i]*y1[i];
    s[i]=sqrt(t);

    }
    for(i=0;i<n;i++)
    printf("%.2f ",s[i]);
    return 0;


    }

    ******************************************************************************************************************888


    1284

    输入输出5(数学函数)
    时间限制(普通/Java):1000MS/3000MS 运行内存限制:65536KByte
    总提交:810 测试通过:536

    描述


    输入平面上两个点的坐标(double类型),计算两个点之间的距离。


    输入

    两个点的坐标(4个实数)。

    输出

    两点之间的距离(保留3位小数)。

    样例输入

    10.5 1.6 3.5 4.8

    样例输出

    7.697

    #include<stdio.h>
    #include<math.h>
    main()
    {double a,b,c,d;
    scanf("%lf%lf%lf%lf",&a,&b,&c,&d);
    printf("%.3lf ",sqrt((a-c)*(a-c)+(b-d)*(b-d)));
    }


    #include<stdio.h>
    #include<math.h>
    main()
    {
    float a,b,c,d,s,t;
    scanf("%f%f%f%f",&a,&b,&c,&d);
    s=(a-c)*(a-c)+(b-d)*(b-d);
    t=sqrt(s);
    printf("%.3f",t);
    }


    #include<stdio.h>
    #include<math.h>
    int main()
    {
    double x,y, m,n,d;
    scanf("%lf%lf",&x,&y);
    scanf("%lf%lf",&m,&n);
    d=sqrt((x-m)*(x-m)+(y-n)*(y-n));
    printf("%.3lf ",d);
    }


    #include <iostream>
    #include <cmath>
    #include <iomanip>
    using namespace std;
    int main(int argc, char *argv[])
    {
    double x1,x2,y1,y2;
    cin>>x1>>y1>>x2>>y2;
    cout<<fixed<<setprecision(3);
    cout<<sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))<<endl;
    return 0;
    }


    #include<math.h>
    #include<stdio.h>
    void main()
    {
    float a,b,c,d;
    double s;
    scanf("%f %f %f %f",&a,&b,&c,&d);
    s=sqrt((a-c)*(a-c)+(b-d)*(b-d));


    printf("%.3f ",s);
    }

  • 相关阅读:
    VS使用技巧
    写的一个简单定时器(非独立线程)
    C/C++技巧
    【转载】R6034错误,C Runtime Error
    C/C++面试题(一)
    常用的coco2d-x游戏开发工具(转)
    AndroidJNI 调用JAVA(转)
    Android SDK +Eclipse+ADT+CDT+NDK 开发环境在windows 7下的搭建
    简单的字符串压缩--C代码
    SQLite: sqlite_master(转)
  • 原文地址:https://www.cnblogs.com/2014acm/p/3901481.html
Copyright © 2011-2022 走看看