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<cstring> #include<algorithm> #include<cmath> #define long long ll using namespace std; double Dist(int x, int y) { double dis = 0; double a = sqrt(2); for(int i = 1; i < x+y; ++i) { dis += a*i; } dis += a*x; for(int i = 0; i < x+y; ++i) { dis += sqrt(i*i+(i+1)*(i+1)); } return dis; } int main() { int t; scanf("%d", &t); while(t--) { int x1, x2, y1, y2; scanf("%d%d%d%d", &x1, &y1, &x2, &y2); printf("%.3lf\n",abs(Dist(x2,y2)-Dist(x1,y1))); } return 0; }