您的位置:首页 > 其它

HDU 2073 无限的路

2016-06-04 15:45 405 查看
点击打开链接

无限的路

[b]Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 8081    Accepted Submission(s): 4193
[/b]

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



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

[align=left]Input[/align]
第一个数是正整数N(≤100)。代表数据的组数。

每组数据由四个非负整数组成x1,y1,x2,y2;所有的数都不会大于100。

 

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

[align=left]Sample Input[/align]

5
0 0 0 1
0 0 1 0
2 3 3 1
99 99 9 9
5 5 5 5

 

[align=left]Sample Output[/align]

1.000
2.414
10.646
54985.047
0.000

 

[align=left]Author[/align]
Lily
 

[align=left]Source[/align]
浙江工业大学网络选拔赛

 

#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <algorithm>
#define sq sqrt(2)
using namespace std;

double dis(int a, int b) {
return sqrt((double)a*a + (double)(b*b));
}
int main() {
int t;
int x1, x2, y1, y2, temp;
scanf("%d", &t);
while (t--) {
int c1, c2;
double ans = 0;
scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
c1 = (x1 + y1);
c2 = (x2 + y2);
if (c1 > c2) {
temp = c1;
c1 = c2;
c2 = temp;
temp = x1;
x1 = x2;
x2 = temp;
temp = y1;
y1 = y2;
y2 = temp;
}
if (c1 == c2) {
printf("%.3lf\n",(double) sq * (x2 - x1));
continue;
}
for (int i = c1; i < c2; i++) {
ans += dis(i, i + 1) + (i + 1) * sq;
}
ans += sq * y1 - sq * y2;
printf("%.3lf\n", ans);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  acm 杭电