fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int s,n,h=0;
  4. double ans=0;
  5. struct NODE{
  6. int x, y;
  7. bool operator<(const NODE rhs)const{
  8. return x<rhs.x; }
  9. } node[100];
  10. int main() {
  11. cin>>s;
  12. while(s--){
  13. cin>>n;
  14. h=0,ans=0;
  15. cin>>node[0].x>>node[0].y;
  16. for(int i=1;i<n;i++){
  17. cin>>node[i].x>>node[i].y;
  18. }
  19. sort(node,node+n);
  20. for(int i=n-2;i>=0;i--){
  21.  
  22. if(node[i+1].y<node[i].y and node[i].y>h){
  23. //cout<<node[i].x<<endl;
  24. ans+=sqrt( (node[i].x-node[i+1].x)*(node[i].x-node[i+1].x) + (node[i].y-node[i+1].y)*(node[i].y-node[i+1].y) )/(node[i].y-node[i+1].y)*(node[i].y-h);
  25. h=node[i].y;
  26. }
  27. }
  28. cout<<fixed<<setprecision(2)<<ans<<endl;
  29.  
  30. }
  31.  
  32. return 0;
  33. }
Success #stdin #stdout 0.01s 5288KB
stdin
2
11
1100 1200
0 500
1400 100
600 600
2800 0
400 1100
1700 600
1500 800
2100 300
1800 700
2400 500
2
0 1000
1000 0
stdout
1446.34
1414.21