5 0 0 0 1 0 0 1 0 2 3 3 1 99 99 9 9 5 5 5 5
1.000 2.414 10.646 54985.047 0.000
打出了所有点到上一个点的距离,然后求点之间的距离的时候,就转化成这两个点到原点距离之差就行了。
代码如下:
#include <cstdio> #include <cmath> int main() { double a[21000]; a[1] = 0; a[2] = 1; double b1 = 1; double b2 = 2; int num = 1; int t = num; for (int i = 3 ; i <= 21000 ; i++) { if (t != 0) { a[i] = sqrt(2.0); t--; } else { a[i] = sqrt (b1*b1 + b2*b2); b1++; b2++; num++; t = num; } } // for (int i = 1 ; i <= 40 ; i++) // printf ("%.3lf ",a[i]); int u; scanf ("%d",&u); while (u--) { int x1,x2,y1,y2; scanf ("%d %d %d %d",&x1,&y1,&x2,&y2); int n1,n2; n1 = (1 + x1 + y1) * (x1 + y1) / 2 + x1 + 1; n2 = (1 + x2 + y2) * (x2 + y2) / 2 + x2 + 1; if (n2 < n1) { int k; k = n1; n1 = n2; n2 = k; } else if (n1 == n2) { printf ("0\n"); continue; } double ans = 0; for (int i = n1+1 ; i <= n2 ; i++) ans += a[i]; printf ("%.3lf\n",ans); } return 0; }