zoukankan      html  css  js  c++  java
  • 【UVALive 11300】

    题目链接:http://acm.hust.edu.cn:8080/judge/problem/viewProblem.action?id=15133

    题目大意:给一个周长为10000的园,圆上等距分布着n个雕塑,现在要新增m个雕塑,要求n+m个雕塑最终也等距,问如何移动这n个雕塑的部分雕塑,让其移动总距离和最小。

    解题思路:先计算让n+m个雕塑固定(周长是固定的),因为雕塑最终要移到这些位置。再从n+m个点中选择一个固定点,以它为起始再对n-1个点进行圆周上等距分布。这两种情况下的点不一样,可以记为黑与白,让n-1个白点移到离本点最近的黑点算出来的移动距离总和就是最小了。

    小知识: floor:下位取整,即取小于等于x的最大整数。

                ceil : 上位取整,即取大于x的最小整数。

     

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cmath>
     4 #include <algorithm>
     5 #include <cstring>
     6 using namespace std;
     7 
     8 int main()
     9 {
    10      int  n, m;
    11      while(scanf("%d%d",&n,&m)==2)
    12      {
    13          double ans=0.0;
    14          for(int i=1; i<n; i++)
    15          {
    16              double  p=double(i)/n*(n+m);  //一个点固定,n-1(2~n)个起始点的坐标
    17              ans+=fabs(p-floor(p+0.5))/(n+m);
    18          }
    19          printf("%.4lf\n",ans*10000);  //等比例扩大坐标
    20      }
    21      return 0;
    22 }

     

     

  • 相关阅读:
    P2622 关灯问题II(关灯问题)
    P1140 相似基因
    Choose and Divide UVa 10375
    Disgruntled Judge UVA
    Color Length UVA
    P1052 过河
    P1026 统计单词个数
    Balanced Number HDU
    The SetStack Computer UVA
    Urban Elevations UVA
  • 原文地址:https://www.cnblogs.com/kane0526/p/2764090.html
Copyright © 2011-2022 走看看