hdu 2073

来源:互联网 发布:淘宝客服基本培训内容 编辑:程序博客网 时间:2024/06/05 09:09

无限的路

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3879    Accepted Submission(s): 1993


Problem Description
甜甜从小就喜欢画图画,最近他买了一支智能画笔,由于刚刚接触,所以甜甜只会用它来画直线,于是他就在平面直角坐标系中画出如下的图形:



甜甜的好朋友蜜蜜发现上面的图还是有点规则的,于是他问甜甜:在你画的图中,我给你两个点,请你算一算连接两点的折线长度(即沿折线走的路线长度)吧。
 

Input
第一个数是正整数N(≤100)。代表数据的组数。
每组数据由四个非负整数组成x1,y1,x2,y2;所有的数都不会大于100。
 

Output
对于每组数据,输出两点(x1,y1),(x2,y2)之间的折线距离。注意输出结果精确到小数点后3位。
 

Sample Input
50 0 0 10 0 1 02 3 3 199 99 9 95 5 5 5
 

Sample Output
1.0002.41410.64654985.0470.000
 

Author
Lily
 

Source
浙江工业大学网络选拔赛
 

Recommend
linle


//先求每个点到原点的距离,然后相减。#include <stdio.h>#include <math.h>double distoorg(int x, int y){int i, s;double dis = 0;s = x + y;dis += s * (s -1) * sqrt(2) / 2;for(i = s; i > 0; i--)dis += sqrt(i*i + (i-1)*(i-1));dis += x*sqrt(2);return dis;}int main(){int n, x1, y1, x2, y2;scanf("%d", &n);while(n--){scanf("%d%d%d%d", &x1, &y1, &x2, &y2);printf("%.3lf\n", fabs(distoorg(x1, y1) - distoorg(x2, y2)));}return 0;}

原创粉丝点击