首页 > ACM题库 > HDU-杭电 > HDU 4355-Party All the Time-图-[解题报告]HOJ
2015
05-23

HDU 4355-Party All the Time-图-[解题报告]HOJ

Party All the Time

问题描述 :

In the Dark forest, there is a Fairy kingdom where all the spirits will go together and Celebrate the harvest every year. But there is one thing you may not know that they hate walking so much that they would prefer to stay at home if they need to walk a long way.According to our observation,a spirit weighing W will increase its unhappyness for S3*W units if it walks a distance of S kilometers.
Now give you every spirit’s weight and location,find the best place to celebrate the harvest which make the sum of unhappyness of every spirit the least.

输入:

The first line of the input is the number T(T<=20), which is the number of cases followed. The first line of each case consists of one integer N(1<=N<=50000), indicating the number of spirits. Then comes N lines in the order that x[i]<=x[i+1] for all i(1<=i<N). The i-th line contains two real number : Xi,Wi, representing the location and the weight of the i-th spirit. ( |xi|<=106, 0<wi<15 )

输出:

The first line of the input is the number T(T<=20), which is the number of cases followed. The first line of each case consists of one integer N(1<=N<=50000), indicating the number of spirits. Then comes N lines in the order that x[i]<=x[i+1] for all i(1<=i<N). The i-th line contains two real number : Xi,Wi, representing the location and the weight of the i-th spirit. ( |xi|<=106, 0<wi<15 )

样例输入:

1
4
0.6 5
3.9 10
5.1 7
8.4 10

样例输出:

Case #1: 832

(/ □ \)。。。。之前标题一不小心写成整了好久的4351了……被标题“骗进来”的童鞋不好意思。。

由于“不高兴值”的图像为单峰函数(二次导恒为正或负,其实我没有证,是别人告诉我的……好像是设目标点为p,|Xi – P|^3 * Wi 由各种拆开求导可得,数学现在力不从心……伤心T T),所以三分可解,精确到0.001便可

#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
const int N = 10e4+1;
const float eps = 1e-2;
struct po
{
    double x;
    double w;
} point[N];
int main()
{
//    freopen("1006.txt","r",stdin);
    int t;
    scanf("%d",&t);
    for(int cases = 1; cases<=t; cases++)
    {
        int n;
        scanf("%d",&n);
        for(int i=1; i<=n; i++)
            scanf("%lf %lf",&point[i].x,&point[i].w);
        double low = point[1].x;
        double high = point[n].x;
        double sum1 = 10;
        double sum2 = 0;
        while(fabs(sum1-sum2)>eps)
        {
            double mid1 = low + (high-low)/3;
            double mid2 = high - (high-low)/3;
            sum1 = sum2 = 0;
            for(int i=1; i<=n; i++)
            {
                sum1 += pow((fabs(point[i].x - mid1)),3)*point[i].w;
                sum2 += pow((fabs(point[i].x - mid2)),3)*point[i].w;
            }
            if(sum1<sum2)
                high = mid2;
            else if(sum1>sum2)
                low = mid1;
            else if(sum1==sum2)
                low = high;
        }
        printf("Case #%d: %.0lf\n",cases,sum1);
    }
    return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

参考:http://blog.csdn.net/h2952220/article/details/7854391


,
  1. 纯种美国血统……这同学叫我感觉很纠结,美国本来就是外来移民的国家,如果非要说本土纯粹的话,我理解应该是印第安人血统了。

  2. 纯种美国血统……这同学叫我感觉很纠结,美国本来就是外来移民的国家,如果非要说本土纯粹的话,我理解应该是印第安人血统了。

  3. 纯种美国血统……这同学叫我感觉很纠结,美国本来就是外来移民的国家,如果非要说本土纯粹的话,我理解应该是印第安人血统了。

  4. 纯种美国血统……这同学叫我感觉很纠结,美国本来就是外来移民的国家,如果非要说本土纯粹的话,我理解应该是印第安人血统了。

  5. 纯种美国血统……这同学叫我感觉很纠结,美国本来就是外来移民的国家,如果非要说本土纯粹的话,我理解应该是印第安人血统了。

  6. 纯种美国血统……这同学叫我感觉很纠结,美国本来就是外来移民的国家,如果非要说本土纯粹的话,我理解应该是印第安人血统了。

  7. 纯种美国血统……这同学叫我感觉很纠结,美国本来就是外来移民的国家,如果非要说本土纯粹的话,我理解应该是印第安人血统了。

  8. 纯种美国血统……这同学叫我感觉很纠结,美国本来就是外来移民的国家,如果非要说本土纯粹的话,我理解应该是印第安人血统了。