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. Linux系统——引导过程与服务控制

    一.Linux开机启动原理(十步) (1)开机自检BIOS 开机检测,主板检测 (2)MBR引导 硬盘512字节 (3)GRUB菜单 操作系统菜单 (4)加载内核(kernel) 启动操作系统核心,根 ...

  2. SQL Server创建事务——锁

    参考地址:http://www.cnblogs.com/knowledgesea/p/3714417.html 事务定义: 事务是作为单个逻辑单元执行的一系列操作,它是一个不可分割的工作逻辑单元.它包 ...

  3. PL/SQL编程—存储过程

    SQL> create or replace procedure sp_pro3(name_in varchar2,id_in varchar2) is begin update mytest ...

  4. springer论文模板参考文献的顺序问题

    latex环境 MikTex 2.9 + TeXstudio 2.12.8 (+ Mendeley) 问题 springer提供的latex模板 中最后的参考文献是按照字母顺序排列的.我想要弄成按照文 ...

  5. CIFAR和SVHN在各CNN论文中的结果

    CIFAR和SVHN结果 加粗表示原论文中该网络的最优结果. 可以看出DenseNet-BC优于ResNeXt优于DenseNet优于WRN优于FractalNet优于ResNetv2优于ResNet ...

  6. Linux 日志分析工具(logwatch)安装及使用

    Linux 日志分析工具(logwatch)安装及使用 日志是非常重要的系统文件,管理员每天的重要工作就是分析和查看服务器的日志,判断服务器的健康状态.但是日志管理又是一项非常枯燥的工作,如果需要管理 ...

  7. Java伙伴系统(模拟)

    参考:https://labrick.cc/2015/10/12/buddy-system-algorithm/ 代码过烂 不宜参考. output: [operating.entity.Heap@4 ...

  8. 20145103《JAVA程序设计》课程总结

    每周读书笔记链接汇总 假期笔记 http://www.cnblogs.com/20145103fwh/p/5248170.html 第一周读书笔记 http://www.cnblogs.com/201 ...

  9. Jquery10 高级事件

    学习要点: 1.模拟操作 2.命名空间 3.事件委托 4.on.off 和 one jQuery 不但封装了大量常用的事件处理,还提供了不少高级事件方便开发者使用.比如模拟用户触发事件.事件委托事件. ...

  10. openwrt如何查看当前使用的硬件平台

    答:输入cat /tmp/sysinfo/board_name即可获取