HDU4355 三分查找
/*
* 三分查找
*/
#include<cstdio>
#include<cmath>
#define eps 1e-6
//typedef __int64 LL;
int n;
double x[50005], w[50005];
double func(double y){
double res=0;
for(int i=0;i<n;i++){
double a=y-x[i];
a=a<0?-a:a;
res+=a*a*a*w[i];
}
return res;
}
int main(){
int T;
scanf("%d",&T);
for(int t=1;t<=T;t++){
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%lf%lf",&x[i],&w[i]);
}
double l=x[0],r=x[n-1],mid,mmid;
while(r-l>eps){
mid=(l+r)/2.0;
mmid=(mid+r)/2.0;
if(func(mid)-func(mmid)>eps){
l=mid;
}
else{
r=mmid;
}
}
printf("Case #%d: %lld\n",t,(long long)(func(r)+0.5));
//hdu要用int64
}
}
最新文章
- phpcms中的RBAC权限系统
- nginx 基本操作
- java UDP
- AFNetworking 基本使用
- CLGeocoder "Lost connection to geod" #error# when use geocodeAddressString:completionHandler
- Maven学习总结(二)——Maven项目构建过程练习
- AC自动机 - 多模式串的匹配运用 --- HDU 3065
- php向队列服务里插入一条insert sql例如
- io资料
- mysql---整体备份和增量备份
- ORACLE模拟临时文件、日志成员、口令文件丢失情况与恢复【weber出品】
- 中小企业为什么要上HR系统
- OpenGL——OpenCV与SOIL读取图片进行纹理贴图
- 2019-4-26 css学习笔记
- SpringMVC @SessionAttributes 使用详解以及源码分析
- (笔记)Ubuntu下安装arm-linux-gcc-4.4.3.tar.gz (交叉编译环境)
- 地址解析协议ARP(Address Resolution Protocol)
- global statement
- IStat Menus 5.02 5.03 的注册码
- 3.10 Templates -- Development Helpers