HDU 4355 Party All the Time
来源:互联网 发布:淘宝网折800女士皮草 编辑:程序博客网 时间:2024/05/18 11:46
http://acm.hdu.edu.cn/showproblem.php?pid=4355
题意: 坐标轴上有一些点,每个点有权值,找出一个位置,所有点到这个点的距离的三次方乘以权值的和最小。
用三分求解就可以了
#include <cstdio>#include <cstring>#include <cmath>#include <iostream>#include <algorithm>using namespace std;const double EPS = 1e-4;const int MAXN = 50000+100;int n, T;double a[MAXN];double b[MAXN];double maxlen(double t) { double ans = 0; for(int i = 0; i < n; ++i){ans += (a[i]-t)*(a[i]-t)*((fabs)(a[i]-t))*b[i];} return ans;}int main() { scanf("%d", &T); for(int t = 1; t <= T; ++t) { scanf("%d", &n); for(int i = 0; i < n; ++i) {scanf("%lf %lf",&a[i],&b[i]);} double l = -1e6 , r = 1e6; while(l + EPS < r) { double m1 = l + (r - l) / 3; double m2 = r - (r - l) / 3; if(maxlen(m1) < maxlen(m2)) r = m2; else l = m1; }printf("Case #%d: %.0lf\n", t, maxlen(l)); }return 0;}
0 0
- hdu 4355 Party All the Time
- hdu 4355 Party All the Time
- HDU 4355 - Party All the Time
- hdu 4355 party all the time 三分法
- HDU 4355 Party All the Time 三分
- hdu 4355 Party All the Time (三分)
- HDU 4355 Party All the Time 三分
- hdu 4355 Party All the Time
- hdu 4355 Party All the Time 三分
- HDU 4355 Party All the Time
- HDU 4355 Party All the Time
- HDU 4355 Party All the Time
- HDU 4355 Party All the Time(三分)
- Party All the Time HDU
- HDU 4355 Party All the Time(三分)
- HDU 4355 Party All the Time(三分)
- HDU 4355 - Party All the Time(三分)
- HDU 4355 Party All the Time(三分|二分)
- Maven 下载jar包的同时自动下载源码包source.jar
- LeetCode 317. Shortest Distance from All Buildings(最短建筑距离)
- el表达式
- AndroidStudio GreenDao简单使用Demo
- C# 调用C++工程生成的DLL
- HDU 4355 Party All the Time
- popupWindow 弹出动画效果
- 官文:从今天开始开发iOS应用(Swift)第一章1~3节纯中文
- DOS源码相关资料
- mybatis配置insert/update/delete同一个模板
- js 自定义日期(Date)格式化
- Android动画机制与使用技巧
- 关于某些进程使adb不能正常工作
- 2016春季练习——二分+贪心