Party All the Time

Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5791    Accepted Submission(s): 1841

Problem Description
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.
 
Input
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 )
 
Output
For each test case, please output a line which is "Case #X: Y", X means the number of the test case and Y means the minimum sum of unhappyness which is rounded to the nearest integer.
 
Sample Input
1
4
0.6 5
3.9 10
5.1 7
8.4 10
 
Sample Output
Case #1: 832
 
Author
Enterpaise@UESTC_Goldfinger
 
Source
     求Y=Σw=Σ(wi*|xi-X|3) 使得Y达到最小的那个Ymin.
    注意到这个函数不是单调的,所以二分不可行,要用三分来做,mid=(l+r)/2,mid2=(mid+r)/2,然后f(x)较大的那个点作为新的l/r边界,慢慢缩小范围。
     

 #include<bits/stdc++.h>
using namespace std;
#define sf(a) scanf("%d",&a)
double x[],w[];
int N;
double cal(double X)
{
double r=;
for(int i=;i<=N;++i){
double t=fabs(X-x[i]);
r+=w[i]*t*t*t;
}
return r;
}
int main()
{
int t,i,j,k;
int cas=;
cin>>t;
while(t--){
cin>>N;
for(i=;i<=N;++i)
scanf("%lf%lf",x+i,w+i);
double l=-,r=;
for(i=;i<=;++i){
double mid=(l+r)/;
double mid2=(mid+r)/;
if(cal(mid)<cal(mid2)){
r=mid2;
}
else{
l=mid;
}
}
printf("Case #%d: %.0f\n",++cas,cal(l));
}
return ;
}

HDU-4355-三分的更多相关文章

  1. codeforces 782B The Meeting Place Cannot Be Changed+hdu 4355+hdu 2438 (三分)

                                                                   B. The Meeting Place Cannot Be Change ...

  2. HDU 2298 三分

    斜抛从(0,0)到(x,y),问其角度. 首先观察下就知道抛物线上横坐标为x的点与给定的点的距离与角度关系并不是线性的,当角度大于一定值时可能会时距离单调递减,所以先三分求个角度范围,保证其点一定在抛 ...

  3. HDU 5144 三分

    开始推导用公式求了好久(真的蠢),发现精度有点不够. 其实这种凸线上求点类的应该上三分法的,当作入门吧... /** @Date : 2017-09-23 21:15:57 * @FileName: ...

  4. hdu 4355 Party All the Time(三分搜索)

    Problem Description In the Dark forest, there is a Fairy kingdom where all the spirits will go toget ...

  5. HDU 4355 Party All the Time (三分求极值)

    题意:给定x轴上有n个点,每一个点都有一个权值,让在x轴上选一个点,求出各点到这个点的距离的三次方乘以权值最小. 析:首先一开始我根本不会三分,也并没有看出来这是一个三分的题目的,学长说这是一个三分的 ...

  6. HDU 4355——Party All the Time——————【三分求最小和】

    Party All the Time Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  7. HDU 4355 Party All the Time(三分|二分)

    题意:n个人,都要去參加活动,每一个人都有所在位置xi和Wi,每一个人没走S km,就会产生S^3*Wi的"不舒适度",求在何位置举办活动才干使全部人的"不舒适度&quo ...

  8. HDU 4355:Party All the Time(三分模板)

    Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s) ...

  9. hdu 4717(三分求极值)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4717 思路:三分时间求极小值. #include <iostream> #include ...

  10. hdu 4717(三分) The Moving Points

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=4717 n个点,给出初始坐标和移动的速度和移动的方向,求在哪一时刻任意两点之间的距离的最大值的最小. 对于最 ...

随机推荐

  1. jenkins git gradle android自动化构建配置

    需要安装软件(jenkins所在服务器): gradle.SDK 一.gradle安装(服务器部署的gradle版本需要等于或高于开发环境的gradle版本) 1.下载地址:http://servic ...

  2. Linux服务器access_log日志分析及配置详解(一)

    nginx的log日志分为access log 和 error log 其中access log 记录了哪些用户,哪些页面以及用户浏览器.ip和其他的访问信息 error log 则是记录服务器错误日 ...

  3. 聊一聊 Django 中间件

    Django默认的Middleware有七个: MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'django.cont ...

  4. C# 将 HTML 转换为图片或 PDF

    首先是把 HTML 转换为图片. public partial class Form1 : Form { public Form1() { InitializeComponent(); } WebBr ...

  5. CDOJ 1287 MC挖矿世界(Spfa+set优化)

    题目大意:原题链接 解题思路:此题要求多点最短距离,但是直接套用floyd会超时. 然后我们想直接从每一个点开始bfs就好了,但是还是会TLE,为什么呢? 因为你访问了很多次没有意义的地方,因为有些点 ...

  6. Salesforce学习第一天

    好久没有在博客园发布学习博客了,开学事情多,奇葩心思多嘛,谅解.现在在一家公司实习Salesforce开发,每天都在看英文文档,然后学着操作,只可惜没人能培训下,学习起来进度比较慢.英文的文档看的思绪 ...

  7. 这几天添加ccbi 出现的问题

    父类是一个ccbi...在父类的onNodeLoaded 里面添加子类的ccbi ... 出现了父类为空的情况...获取不到时间轴..动画为空... 需要在父类的onEnter里面写添加子类的ccbi ...

  8. TOSCA自动化测试工具--识别元素唯一性的控件

    当Modules模块通过Scan识别出页面元素后,选择需要测试的对象,然后判断对象唯一性

  9. 在python3下使用OpenCV 抓取摄像头图像提取蓝色

    工作中需要对摄像头进行调试, Python平台大大提高调试效率. 从网找到段代码, 可以从摄像头图像中抠出蓝色. import cv2 import numpy as np cap  = cv2.Vi ...

  10. python 打印 九九表

    用Python 打印九九表. print 每打印一行默认会带有换行, 在print语句后加上,end = 't' 会变成tab. 排版会好点. def main(): for i in range(1 ...