【二分】LED

题目描述

A Light-Emitting Diode (LED) is a semiconductor light source, which emits light when an electric current of voltage higher than a threshhold is applied to its leads. ACM R&D recently reported that they have succesfully developed a new LED, namely, ACMOLED. An ACMOLED has a special behavior that the intensity of light emitted from it changes in two steps as the voltage of the electric current increases, as depicted in the graph below.

As shown, an ACMOLED is not activated in the voltage range from 0 to V1, while it emits light with intensity L1 ≥ 0 when the voltage reaches the first threshold V1 and light with intensity L2 ≥ L1 when the voltage reaches the x threshold V2. More specifically, if F(v) is the function that maps voltage v to the intensity of light emitted from an ACMOLED, then for four real numbers L1, L2, V1, and V2 with 0 ≤ L1 ≤ L2 and 0 < V1 < V2, we have

The very issue now is that ACM R&D still does not know the exact values of two threshold voltage values V1 and V2 and the two intensity values L1 and L2 as well. Researchers in ACM R&D plan to estimate these four values for ACMOLEDs by repeated experiments.
Experiments are performed by applying current of a specific voltage and observing the intensity of light emitted from an ACMOLED. After n repeated experiments with different voltage values, obtained are the data of n tuples (v1, l1), (v2, l2), ..., (vn, ln), where li is the observed intensity for voltage vi. Due to the impreciseness of the observing device and other reasons, the experimental data are not accurate and may contain some error. Nonetheless, they want to find a best estimated intensity function F(v) that minimizes the following error function:

where |x| denotes the absolute value of a real number x.
For a given data of n tuples, write a program that finds an estimated intensity function F that minimizes the above error function and outputs the value of error(F).

 

输入

Your program is to read from standard input. The input starts with a line containing an integer n (1 ≤ n ≤ 300,000), where n is the number of tuples (vi, li) in the experimental data. In the following n lines, each line contains two integers, which range inclusively from 0 to 109, representing vi and li in each tuple (vi, li) of the experimental data. Note that you may assume that there are no two tuples (vi, li) and (vj, lj) in the input such that 1 ≤ i < j ≤ n and vi = vj.

 

输出

Your program is to write to standard output. Print exactly one line consisting of one real number, rounded to the first decimal place, which represents the minimum value of error(F).

 

样例输入

复制样例数据

5
0 0
2 1
3 5
6 7
7 11

样例输出

1.0

题目大意:

此题大体上就是在第一象限内给出n个点,输入第一行为n,下面n行为这n个点的坐标,现在要找出一个函数,形如图中给的阶梯型,要使的这些点到这个分段阶梯的距离的最大值最小化,并求出这个最小化的最大值。

解题思路:

此题是一道二分的题,我们可以通过二分点的误差范围,通过判断是否可以由这样三条直线来构成,来确定二分的条件,但需要注意的是,若第一个点的横坐标为0,即其在y轴上时,需要将左边界改为此时点的y值,因为此时这个点一定是落在第一条线段上的。

代码:

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <bitset>
#include <set>
#include <utility>
#include <sstream>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define inf 0x3f3f3f3f
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define lep(i,l,r) for(int i=l;i>=r;i--)
#define ms(arr) memset(arr,0,sizeof(arr))
//priority_queue<int,vector<int> ,greater<int> >q;
const int maxn = (int)1e5 + 5;
const ll mod = 1e9+7;
struct node
{double x,y;double up,down;
}arr[300100];
bool cmp(node a,node b) {return a.x<b.x;
}
int n;
bool judge(double d) {int t;rep(i,1,n) {if(arr[i].y-d>0) {     //将能放在第一条线段上的的点先去掉,即放在x轴上的t=i;break;}}int num=1;double up=arr[t].y+d,down=arr[t].y-d;for(int i=t+1;i<=n;i++) {if(arr[i].y+d<down) {       //此时不满足情况,即当前的点在线段下面了return false;}else if(arr[i].y-d>up) {      //当前的点在此时线段渠道的范围之上,需开一条新的线段num++;if(num>2) return false;up=arr[i].y+d;          //更新线段所在的区间down=arr[i].y-d;}else {up=min(up,arr[i].y+d);      //缩小线段所在的区间down=max(down,arr[i].y-d);}}return true;
}
int main() 
{#ifndef ONLINE_JUDGEfreopen("in.txt", "r", stdin);#endif//freopen("out.txt", "w", stdout);ios::sync_with_stdio(0),cin.tie(0);scanf("%d",&n);double maxy=-1;rep(i,1,n) {scanf("%lf %lf",&arr[i].x,&arr[i].y);maxy=max(maxy,arr[i].y);}sort(arr+1,arr+1+n,cmp);double l=0,r=maxy;if(arr[1].x==0) l=arr[1].y;while(r-l>0.00001) {double mid=(l+r)/2.0;if(judge(mid)) {r=mid;}else l=mid;}printf("%.1f\n",r);return 0;
}

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/536302.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【差分数组】Master of GCD

题目描述 Hakase has n numbers in a line. At fi rst, they are all equal to 1. Besides, Hakase is interested in primes. She will choose a continuous subsequence [l, r] and a prime parameter x each time and for every l≤i≤r, she will change ai into ai*x. To…

【模拟】Ground Defense

题目描述 You are a denizen of Linetopia, whose n major cities happen to be equally spaced along an east-west line. In fact, they are often numbered in order from 1 to n, where 1 is the westmost city and n is the eastmost city. Linetopia was a lovely plac…

【模拟】Bulbs

题目描述 Greg has an m n grid of Sweet Lightbulbs of Pure Coolness he would like to turn on. Initially, some of the bulbs are on and some are off. Greg can toggle some bulbs by shooting his laser at them. When he shoots his laser at a bulb, it toggles th…

【模拟】Ingenious Lottery Tickets

题目描述 Your friend Superstitious Stanley is always getting himself into trouble. This time, in his Super Lotto Pick and Choose plan, he wants to get rich quick by choosing the right numbers to win the lottery. In this lottery, entries consist of six dis…

【数学】Hunter’s Apprentice

题目描述 When you were five years old, you watched in horror as a spiked devil murdered your parents. You would have died too, except you were saved by Rose, a passing demon hunter. She ended up adopting you and training you as her apprentice. Rose’s cur…

【模拟】Thanks, TuSimple!

题目链接&#xff1a;http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId5979 Thanks, TuSimple! Time Limit: 1 Second Memory Limit: 65536 KB In the very first sentence of the very first problem, we would like to give our sincere thanks to TuSimple,…

【二维差分】Monitor

Monitor 题目&#xff1a;http://acm.hdu.edu.cn/showproblem.php?pid6514 Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 163840/163840 K (Java/Others) Total Submission(s): 600 Accepted Submission(s): 190 Problem Description Xiaoteng has a la…

【数学】MORE XOR

Given a sequence of nnn numbers a1,a2,⋯&ThinSpace;,ana_1, a_2,\cdots, a_na1​,a2​,⋯,an​ and three functions. Define a function f(l,r)f(l,r)f(l,r) which returns ⊕a[x](l≤x≤r)\oplus a[x] (l \le x \le r)⊕a[x](l≤x≤r). The \oplus⊕ represents excl…

【数学】Element Swapping

Element Swapping Time Limit: 1 Second Memory Limit: 65536 KB DreamGrid has an integer sequence a1,a2,a3,…,ana_1,a_2,a_3,\dots,a_na1​,a2​,a3​,…,an​ and he likes it very much. Unfortunately, his naughty roommate BaoBao swapped two elements aia_iai​ an…

【二分+二维前缀和】Largest Allowed Area

Largest Allowed Area 时间限制: 1 Sec 内存限制: 128 MB 提交: 146 解决: 54 [提交] [状态] [命题人:admin] 题目描述 A company is looking for land to build its headquarters. It has a lot of money and can buy as many land patches as it needs. Its goal, howev…

【数学】Floating-Point Hazard

Floating-Point Hazard 时间限制: 1 Sec 内存限制: 128 MB 提交: 106 解决: 42 [提交] [状态] [命题人:admin] 题目描述 Given the value of low, high you will have to find the value of the following expression: If you try to find the value of the above express…

【manacher】Strings in the Pocket

Strings in the Pocket Time Limit: 1 Second Memory Limit: 65536 KB BaoBao has just found two strings ss1s2…snss_1s_2\dots s_nss1​s2​…sn​ and tt1t2…tntt_1t_2\dots t_ntt1​t2​…tn​ in his left pocket, where sis_isi​ indicates the iii-th character in…

【并查集+dp】Team

Team 时间限制: 1 Sec 内存限制: 128 MB 提交: 124 解决: 10 [提交] [状态] [命题人:admin] 题目描述 ACM-ICPC is a interesting game. A team takes part in this game must consist of exactly (no more and no less) three players. Every year, many new members wil…

【线段树】Segment Tree

Segment Tree 时间限制: 1 Sec 内存限制: 512 MB 提交: 107 解决: 23 [提交] [状态] [命题人:admin] 题目描述 Mcginn opens the code which he wrote 25 years ago. Clever Mcginn wants to know how many positive interger n satisfied that the maximum c can reach w…

UVA1025——A Spy in the Metro【dp】

题目链接&#xff1a;https://cn.vjudge.net/problem/UVA-1025 题目大意&#xff1a;Mario从第1站出发&#xff0c;目的是在时刻T会见车站 nnn 的一个间谍。由于在车站等待容易被抓&#xff0c;所以应尽量躲在开动的火车上&#xff0c;即在车站等待的时间最短&#xff0c;且Ma…

HDU1284——钱币兑换问题【dp】

钱币兑换问题 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 14528 Accepted Submission(s): 8784 Problem Description 在一个国家仅有1分&#xff0c;2分&#xff0c;3分硬币&#xff0c;将钱N兑换成硬…

HDU6092——Rikka with Subset 【dp】

题目网址&#xff1a; https://vjudge.net/problem/HDU-6092 As we know, Rikka is poor at math. Yuta is worrying about this situation, so he gives Rikka some math tasks to practice. There is one of them: Yuta has nn positive A1−AnA1−An and their sum is mm…

洛谷P1725琪露诺【单调队列+dp】

题目描述 在幻想乡&#xff0c;琪露诺是以笨蛋闻名的冰之妖精。 某一天&#xff0c;琪露诺又在玩速冻青蛙&#xff0c;就是用冰把青蛙瞬间冻起来。但是这只青蛙比以往的要聪明许多&#xff0c;在琪露诺来之前就已经跑到了河的对岸。于是琪露诺决定到河岸去追青蛙。 小河可以看…

扶桑号战列舰【RMQ+分治】

扶桑号战列舰 时间限制: 1 Sec 内存限制: 128 MB Special Judge 提交: 197 解决: 63 [提交] [状态] [命题人:admin] 题目描述 众所周知&#xff0c;一战过后&#xff0c;在世界列强建造超无畏级战列舰的竞争之中&#xff0c;旧日本海军根据“个舰优越主义”&#xff0c;建造了扶…

大凤号装甲空母【找规律+矩阵快速幂】

大凤号装甲空母 时间限制: 1 Sec 内存限制: 128 MB 提交: 108 解决: 15 [提交] [状态] [命题人:admin] 题目描述 大凤号航空母舰很喜欢算术。 它&#xff0c;是旧日本海军中最为先进的航空母舰。 它&#xff0c;是旧日本海军中最为短命的航空母舰。 同时&#xff0c;她还是最平…