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. docker镜像上传到阿里云

    目前上传本地镜像到网上有多种途径,一个是上传到hub上,一个是阿里云镜像仓库,还要其他服务器. 上传到hub上实在是太慢了,我的服务器用的是阿里云,所以选择上传到阿里云镜像仓库中. 前提条件:linu ...

  2. php int 与 datetime 转换

    数据库日期类型是int类型的,该查询结果是datetime类型的 select from_unixtime( `dateline` ) from cdb_posts 如果原来类型是datetime类型 ...

  3. How can For each...

    Answer:   I understand the IEnumerator/IEnumerable methods and properties and also how they are inte ...

  4. JSON 转 对象

    Json对象与Json字符串的转化.JSON字符串与Java对象的转换   一.Json对象与Json字符串的转化 1.jQuery插件支持的转换方式: $.parseJSON( jsonstr ); ...

  5. 对于JVM中方法区,永久代,元空间以及字符串常量池的迁移和string.intern方法

    在Java虚拟机(以下简称JVM)中,类包含其对应的元数据,比如类的层级信息,方法数据和方法信息(如字节码,栈和变量大小),运行时常量池,已确定的符号引用和虚方法表. 在过去(当自定义类加载器使用不普 ...

  6. 为什么Eureka Client获取服务实例这么慢

    1. Eureka Client注册延迟 Eureka Client启动后不会立即向Eureka Server注册,而是有一个延迟时间,默认为40s 2. Eureka Server更新响应缓存 Eu ...

  7. zabbix分布式监控系统安装配置

    zabbix简介: zabbix(音同 zæbix)是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案. zabbix能监视各种网络参数,保证服务器系统的安全运营:并提供灵 ...

  8. 4.9版本的linux内核中实时时钟芯片pt7c4338的驱动源码在哪里

    答:drivers/rtc/rtc-ds1307.c,内核配置项为CONFIG_RTC_DRV_DS1307 Location: -> Device Drivers -> Real Tim ...

  9. spark SQL学习(案例-统计每日销售)

    需求:统计每日销售额 package wujiadong_sparkSQL import org.apache.spark.sql.types._ import org.apache.spark.sq ...

  10. CentOs64位编译安装hadoop-2.6.0

    官方提供的hadoop-2.x版本貌似都是32位的,在64位机子下使用可能会报错,最好使用官方提供的源码进行本地编译,编译成适合本地硬件环境的64位软件包. Hadoop是使用Java语言开发的,但是 ...