[sgu]Telecasting station【三分】
来源:互联网 发布:php redis 使用 编辑:程序博客网 时间:2024/05/01 18:20
//Telecasting station 2013.7.22#include <iostream>#include <cstdio>using namespace std;const int MAX = 15005;const double EPS = 1e-6;typedef struct xp{ double x; double p;}xp;int n;xp p[MAX];double fabs(double x){ if(x>0) return x; return (0-x);}double dspl(double m){ double tmp = 0.0; for(int i=0;i<n;i++) { tmp += p[i].p*fabs(p[i].x-m); //cout<<" tmp is "<<tmp; } return tmp;}int main(){ cin>>n; double l=0,r=0; for(int i=0;i<n;i++) cin>>p[i].x>>p[i].p; l = p[0].x; r = p[0].x; for(int i=1;i<n;i++) { if(p[i].x<l) l = p[i].x; if(p[i].x>r) r = p[i].x; } double lm,rm; while(l+EPS<r) { lm = l + (r-l)/3,rm = r - (r-l)/3; double lval = dspl(lm),rval = dspl(rm); //cout<<"lm = "<<lm<<" lval = "<<lval<<" rm = "<<rm<<" rval = "<<rval<<endl; if(lval+EPS<rval) r = rm; else l = lm; } printf("%.5lf\n",lm); return 0;}
三分和二分如出一辙。
函数的单极值性是前提,像这道题就是多个极值,好在任意输出就行。
用结构体也是很自然的事。
浮点数精度的问题。。若将EPS改成1e-5将得到PE。。。嗯。。总之是错的。***
- [sgu]Telecasting station【三分】
- SGU 114. Telecasting station 三分or找中位数
- SGU114 Telecasting station 三分
- sgu114 Telecasting station 三分
- sgu 114 Telecasting station
- [SGU]114. Telecasting station
- Sgu 114 Telecasting station
- SGU 114 Telecasting station
- SGU 114 Telecasting station
- SGU 114 Telecasting station
- 【SGU】 114. Telecasting station 中位数
- SGU 114 Telecasting station 单峰极值函数
- SGU 114 Telecasting station(水~)
- SGU 114 Telecasting station(二分)
- sgu 465 Fire Station Building 三分
- SGU114-Telecasting station
- sgu114:Telecasting station
- 114. Telecasting station
- linux网络socket 接口
- poj 1087 A Plug for UNIX(最大流)
- IE条件注释
- 投资内容简介
- 职场英语:人生道理在职场中的真义
- [sgu]Telecasting station【三分】
- 2>&1
- Android休眠唤醒机制简介(一)
- 千万级并发实现的秘密:内核不是解决方案,而是问题所在!
- win7 cisco vpn无法连接
- S3C2440 PWM设置
- 二维数据表表达式语句
- java 学习07.22 PM IO流
- C语言标准库函数qsort那点小事