HDU 4355-三分
来源:互联网 发布:淘宝同款原理 编辑:程序博客网 时间:2024/06/05 01:09
http://acm.hdu.edu.cn/showproblem.php?pid=4355
题目 给n个人的位置 和 权值w
选 数轴上一实数点, 求每个人到该点的距离dis的三次方*w,的和
让这个和最小。
分析得,为单峰函数,三分解决
#include <cstdio>#include <cmath>#include <cstring>#include <string>#include <algorithm>#include <queue>#include <map>#include <set>#include <vector>#include <iostream>//#include <time.h>using namespace std;const double pi=acos(-1.0);double eps=0.000001;struct node{ double x,w; node() {} node( double a,double b) { x=a,w=b; }};node aa[50005]; int n;double F(double pos){ double ans=0; for (int i=1; i<=n; i++) { double sb=fabs(aa[i].x-pos); ans+=sb*sb*sb*aa[i].w; } return ans;}//double aaa[10005];int main(){ int t; cin>>t; // srand( (unsigned)time( NULL ) );int cnt=1; while(t--) { cin>>n; double x,w; int i; /* for (i=1;i<=n;i++) aaa[i]=rand()%1000*1.5;*/ //sort(aaa+1,aaa+1+n); for (i=1; i<=n; i++) { scanf("%lf %lf",&aa[i].x,&aa[i].w); // aa[i].x=aaa[i]*pow(-1.0,1.0*i); // aa[i].w=rand()%15*1.0; } double l=-1e6; double r=1e6; for (i=0;i<100;i++) { double m1=l+(r-l)/3; double m2=r-(r-l)/3; if (F(m2)>F(m1)) r=m2; else l=m1; } printf("Case #%d: %.0lf\n",cnt++,F(l));/* double minn=F(1); for (i=1;i<=n;i++) { minn= min(minn,F(i)); } long long oo=(long long) (minn); printf("ans2::%lld\n",oo);*/ } return 0;}
0 0
- HDU 4355 三分
- HDU 4355 三分
- HDU 4355-三分
- HDU 4355 (三分算法基础)
- hdu 3400-三分套三分
- HDU 4355 Party All the Time 三分
- hdu 4355 Party All the Time (三分)
- HDU 4355 Party All the Time 三分
- hdu 4355 简单三分找最小值
- hdu 4355 Party All the Time 三分
- HDU 4355 Party All the Time(三分)
- SGU 114 三分 类似于 HDU 4355(4355 同样也是一个三分的题目)
- 【三分】hdu 3400
- HDU 2899 三分查找
- HDU 2438 三分
- HDU 3400 两次三分
- HDU 3756 还是三分
- hdu 3400 三分嵌套
- PHP注销删除Session变量的通用方法
- OBJ-C NSString类介绍及用法学习笔记
- 第7章 消费者、生产者与市场效率
- CodeForces 665C Simple Strings
- HDU 5672 String(尺取法)——BestCoder Round #81(div.1 div.2)
- HDU 4355-三分
- Jquery应用实例
- Win7系统蓝屏常用处理方法
- 高级动画-圆形树展开、收起动画
- CodeForces 665D Simple Subset
- 跟着官方学习Android — Services
- 字符串:可变字符串与不可变字符串
- 广搜(BFS)学习笔记
- HDOJ(HDU) 2061 Treasure the new start, freshmen!(水题、)