zoukankan      html  css  js  c++  java
  • 武汉科技大学ACM :1006: 零起点学算法25——求两点之间的距离

    Problem Description

    输入平面坐标系中2点的坐标,输出它们之间的距离

    Input

    输入4个浮点数x1 y1 x2 y2,分别是点(x1,y1) (x2,y2)的坐标(多组数据)

    Output

    输出它们之间的距离,保留2位小数(每组数据一行)

    Sample Input

    1 0 2 0

    Sample Output

    1.00

     1 #include<stdio.h>
     2 
     3 #include<math.h>
     4 
     5  
     6 
     7 int main()
     8 
     9 {
    10 
    11          float x1,y1,x2,y2;
    12 
    13          double len;
    14 
    15          while(scanf("%f%f%f%f",&x1,&y1,&x2,&y2)!=EOF)
    16 
    17          {
    18 
    19                    len=sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
    20 
    21                    printf("%.2lf
    ",len);
    22 
    23          }
    24 
    25                    return 0;
    26 
    27 }

    其他代码:

     1 #include<stdio.h>
     2 #include<math.h>
     3 int main()
     4 {
     5     double x1,x2,y1,y2;
     6     double distance;
     7     while(scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2)!=EOF)
     8     {
     9         distance=sqrt(fabs(x1-x2)*fabs(x1-x2)+fabs(y1-y2)*fabs(y1-y2));
    10         printf("%.2lf
    ",distance);
    11     }
    12     return 0;
    13 }
  • 相关阅读:
    Codeforces Round #439 (Div. 2)
    Money Systems
    Stamps
    inflate
    多重背包问题
    AIM Tech Round 4 (Div. 2)
    September Challenge 2017
    树的重心
    百度之星2017初赛A
    树上的最大独立集
  • 原文地址:https://www.cnblogs.com/liuwt365/p/4154142.html
Copyright © 2011-2022 走看看