Ultraviolet A-ultraviolet A 1388-Graveyard (mathematical reasoning)

Source: Internet
Author: User

N sculptures are evenly distributed on a circle with a circumference of 10000. Now m sculptures are added to the circle at random, and n + m sculptures are still evenly distributed. This requires moving some of the statues to find the minimum distance of movement.

Method: this is still the example of LIU Da. Assume that a statue does not move and serves as the coordinate origin. The distance from the other statue to the origin is counter-clockwise. Not the actual distance, but the scale-down. The next step is to move to the nearest position. If the example is rounded down, it seems wrong, for example, x = 0.5, y = 1.499999, but the difference between x and y is still less than 1, the distance between adjacent statues is 1, so this is also feasible.

Note: floor and rounding are written.

#include 
 
    #include 
  
     #include 
   
      #include 
    
       #include 
     
        #include 
      
        #include 
       
         #include #include 
        
          using namespace std;int main() { #ifdef Local freopen("a.in", "r", stdin); #endifint n = 0, m = 0, i = 0;while (cin >> n >> m){double ans = 0.0;for (i = 1; i < n; i++){double pos = (double)i/n * (n+m);ans += fabs(pos - floor(pos+0.5)) / (n+m);}cout << setprecision(4) << fixed << ans*10000 << endl;}}
        
       
      
     
    
   
  
 

If the requirements are rigorous, we should be at a distance from the front and back locations. Take a small one and paste the code of a senior friend here, so I will be lazy.

From: http://blog.csdn.net/mr_zys/article/details/17270885

#include 
 
  #include 
  
   #include 
   
    const double len = 10000;int n,m;double d0,d1;int main(){  while(~scanf("%d%d",&n,&m)) {    if(m % n == 0) printf("0.0\n");    else {      d0 = len / (n * 1.0);      d1 = len / ((n + m) * 1.0);      double ans = 0.0;      for(int i = 1; i < n; i++) {double t = i * d0;int d = floor(t/d1);double t1 = fabs(t - d * d1);double t2 = fabs(t - (d + 1.0) * d1);if(t1 > t2) ans += t2;else ans += t1;      }      printf("%.4lf\n",ans);    }  }  return 0;}
   
  
 


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.