HDU2073 无限的路

     这题在计算时就把没一点到第一个点的距离计算出来,再相减就出来了。每条线段都存储起来。

     http://acm.hdu.edu.cn/showproblem.php?pid=2073

  代码如下:

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <iostream>
using namespace std;

double d[10005], D[10005];

double sqrt_2 = sqrt( 2.0 );

double dis( int x, int y )
{
return D[x + y] + d[x + y] - y * sqrt_2;
}

int main()
{
int N;
scanf( "%d", &N );
for( int i = 1, k = 1, j = 1; i < 10005; ++i )
{
d[i] = sqrt( ( double ) k ) + d[i-1];
D[i] = i * sqrt_2 + D[i-1];
k += 4 * i;
}
while( N-- )
{
int x1, y1, x2, y2;
scanf( "%d %d %d %d", &x1, &y1, &x2, &y2 );
printf( "%.3lf\n", fabs( dis( x2, y2 ) - dis( x1, y1 ) ) );
}
return 0;
}
原文地址:https://www.cnblogs.com/Lyush/p/2207740.html