ZOJ 3203 Light Bulb (三分查找)】的更多相关文章

B - Light Bulb Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Practice ZOJ 3203 Description Compared to wildleopard's wealthiness, his brother mildleopard is rather poor. His house is narrow and he has only o…
题意:灯离地面的高度为$H$,人的身高为$h$,灯离墙的距离为$D$,人站在不同位置,影子的长度不一样,求出影子的最长长度. 思路:设人离灯的距离为$x$,当人走到距离灯长度为$L$时,人在墙上的影子消失,此时人再往前走,影子的长度必然会减小,此时的$L$就为三分的左边界,右边界为$R=D$,由形似三角形可以推导出$L=D-\frac{h*D}{H}$,影子的长度 $$f(x)=D-x+H-\frac{(H-h)*D}{x},x\in [D-\frac{h*D}{H},D]$$ 在区间$[D-\…
Light Bulb Time Limit: 1 Second      Memory Limit: 32768 KB Compared to wildleopard's wealthiness, his brother mildleopard is rather poor. His house is narrow and he has only one light bulb in his house. Every night, he is wandering in his incommodio…
Light Bulb Problem's Link:   http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3203 Mean: 灯的位置固定,而人的位置不固定,求人的影子的最大长度. analyse: 当灯.人的头部.右墙角在同一条直线上时,此时人的影子全部在地板上:当人继续往右走的时候,影子分为地板上的和墙上的,由此可见这是一个先增后减的凸函数,三分取最大值即可. double cal(Type a) { return…
如果L全在地面上: 输出 h * D / H 如果L全在墙上: 输出 h 否则: (D - X ) / X = Y / (H - h) L = D - X + h - Y 然后对L求导即可 #include <stdio.h> #include <string.h> #include <math.h> #include <algorithm> using namespace std; int main(){ double H,h,D,x,y,x0; int…
Light Bulb Time Limit: 1 Second      Memory Limit: 32768 KB Compared to wildleopard's wealthiness, his brother mildleopard is rather poor. His house is narrow and he has only one light bulb in his house. Every night, he is wandering in his incommodio…
Compared to wildleopard's wealthiness, his brother mildleopard is rather poor. His house is narrow and he has only one light bulb in his house. Every night, he is wandering in his incommodious house, thinking of how to earn more money. One day, he fo…
Light Bulb Time Limit: 1 Second      Memory Limit: 32768 KB Compared to wildleopard's wealthiness, his brother mildleopard is rather poor. His house is narrow and he has only one light bulb in his house. Every night, he is wandering in his incommodio…
Time Limit: 1 Second      Memory Limit: 32768 KB Compared to wildleopard's wealthiness, his brother mildleopard is rather poor. His house is narrow and he has only one light bulb in his house. Every night, he is wandering in his incommodious house, t…
链接:传送门 题意: 求影子长度 L 的最大值 思路:如果 x = 0 ,即影子到达右下角时,如果人继续向后走,那么影子一定是缩短的,所以不考虑这种情况.根据图中的辅助线外加相似三角形定理可以得到 L = D * (h-x)/(H-x) + x , 再经过一些变形后可知这个 L = D * ( H - h )/( x - H ) + ( x - H ) + H + D ,明显的对号函数在左侧的图像,所以一定是个 凸函数 ,用三分求出极值即可 /**************************…
题目大意: 求L的最大值 思路: 可以想象出是一个关于人到灯泡距离x的单峰上凸函数 当光线在墙角左边的时候影子在不断增长 然后通过相似可以推出人在墙上影子的长度为:H+D*(h-H)/x 再加上地上的D-x就可以计算出每个x的函数值了 #include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> #include<cstring> #include<algorit…
ZOJ Problem Set - 3203 Light Bulb Time Limit: 1 Second      Memory Limit: 32768 KB Compared to wildleopard's wealthiness, his brother mildleopard is rather poor. His house is narrow and he has only one light bulb in his house. Every night, he is wand…
A. Light Bulb Time Limit: 1000ms Case Time Limit: 1000ms Memory Limit: 32768KB   64-bit integer IO format: %lld      Java class name: Main   Compared to wildleopard's wealthiness, his brother mildleopard is rather poor. His house is narrow and he has…
NPY and shot Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1035    Accepted Submission(s): 428   Problem Description NPY is going to have a PE test.One of the test subjects is throwing the sh…
http://codeforces.com/gym/101246/problem/J 题意: 给定x轴上的n个点的坐标,按顺序从左到右给出,现在要使得每个点的间距相同,可以移动每个点的坐标,但是不能改变点的相对顺序.求总共最少需要移动多少距离和移动后点的坐标. 思路: 一开始想到用二分搜索,然后枚举一个点为不动点,但是这样我不知道该怎么去改变L.R的值了.. 仔细想想,这道题目所对应的模型图应该是这样的: 中间存在一点可以使移动距离最短,两边很大,因为间距设置的太小和太大都需要移动很多距离.这道…
Description Compared to wildleopard's wealthiness, his brother mildleopard is rather poor. His house is narrow and he has only one light bulb in his house. Every night, he is wandering in his incommodious house, thinking of how to earn more money. On…
/*  * 三分查找  */ #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;     …
三分: 和二分非常类似的一个算法,与二分不同的是 二分是单调的,而三分是一个先增后减或者先减后增 三分可以求出峰值. 注意三分一定是严格单调的,不能有相等的情况. 讲个例题: 题目 题意: 一个人发现他的影子的长度随着他在灯泡和墙壁之间走到时发生着变化.一个突然的想法出现在脑海里,他想知道他的影子的最大长度. 例图: 输入格式 输入文件的第一行包含一个整数 ,表示测试数据的组数. 对于每组测试数据,仅一行,包含三个实数 , 和 , 表示灯泡的高度, 表示 mildleopard 的身高, 表示灯…
题意:人左右走动,求影子L的最长长度. 思路:三分人在D上的位置.注意影子长=D-x+H-(H-h)*D/x. #include<iostream> #include<stdio.h> #include<stdlib.h> #include<memory.h> #include<string.h> #include<algorithm> #include<cmath> #define clc(a,b) memset(a,b…
题目描述: 如图,你可以在房间里移动,灯泡的高度为H,你的身高为h,灯泡与墙的水平距离为D,求你影子的最长长度(影子长度=地上影子长度+墙上影子长度) 样例输入: 0.5 样例输出: 1.000 0.750 4.000 此题是一道三分模板题 用x表示墙上影子的长度,根据相似三角形可以得到地上的影子长度为(h-x)*d/(H-x) 如图: 三分答案求x即可 #include<iostream> #include<cstdio> #include<cstdlib> #inc…
MS    Memory Limit:65536KB    64bit IO Format:%lld & %llu SubmitStatusid=14946">Practiceid=14946">ZOJ 2976 Description Wildleopard had fallen in love with his girlfriend for 20 years. He wanted to end the long match for their love and…
Light Bulbs Time Limit: 2 Seconds      Memory Limit: 65536 KB Wildleopard had fallen in love with his girlfriend for 20 years. He wanted to end the long match for their love and get married this year. He bought a new house for his family and hired a…
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3203 题意:求影子的最长长度L; 当灯,人头和墙角成一条直线时(假设此时人站在A点),此时的长度是影子全在地上的最长长度.当人再向右走时,影子开始投影到墙上,当人贴着墙,影子长度即为人的高度.所以当人从A点走到墙,函数是先递增再递减,为凸性函数,所以我们可以用三分法来求解. 我们假设:人距离灯的水平距离为x,则不难推出:随着x的变化,L = D - x + H - D *…
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=2899 题意:让你解方程 题解:对于只有一个凸或者没有凸的图像,可以直接上三分解决. #include<cstdio> #include<cmath> ; int t,y; *pow(x,)+*pow(x,)+*pow(x,)+*pow(x,)-y*x;} double three_search(){ ,r=,mid,mmid; while(l+eps<r){ mid=(l+r)/…
托一个学弟的福,学了一下他的最简便三分写法,然后找了一道三分的题验证了下,AC了一题,写法确实方便,还是我太弱了,漫漫AC路!各路大神,以后你们有啥好的简便写法可以在博客下方留个言或私信我,谢谢了! Turn the corner Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3196    Accepted Submission(s…
链接:https://www.nowcoder.com/acm/contest/200/E来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言524288K Special Judge, 64bit IO Format: %lld 题目描述 女装会成瘾 由于某人的精心设计,小可爱掉入了女装的天坑无法自拔. 于是……她开始疯狂的成批的买女装. 而Kirito_Rivaille为了戒掉他的女装病,准备实施家暴——把小可爱的女装从窗户扔下去 他们家距离…
题面 相比 wildleopard 的家,他的弟弟 mildleopard 比较穷.他的房子是狭窄的而且在他的房间里面仅有一个灯泡.每天晚上,他徘徊在自己狭小的房子里,思考如何赚更多的钱.有一天,他发现他的影子的长度随着他在灯泡和墙壁之间走到时发生着变化.一个突然的想法出现在脑海里,他想知道他的影子的最大长度.  思路 首先,分治肯定是能够想到的,但是是二分还是三分呢,我们只需要思考一下就能知道,我们设地上影长为L1,墙上为L2,人走近时L1增加,L2减小,走远时L1减小,L2增加——这是个二次…
LeetCode34. Find First and Last Position of Element in Sorted Array 题意:找出指定元素出现的范围,Ologn 思路:两次二分 class Solution { public: vector<int> searchRange(vector<int>& nums, int target) { , r = nums.size() - ; , rx = -; while (l <= r) { ; if (nu…
也就是loj上的#10016灯泡了... 先上原图: 因为长度肯定是个开口向下的二次函数,所以先是确定用三分来找位置,然后想办法求出当前阴影长度 看到这条斜线,就想到了一次函数,所以就建了一个系,没想到还真解出来了. 首先设灯泡位置为(H,0),再设它与人头之间连接的线段所在直线为y=kx+b 所以b=H(在灯泡处入x=0代可以解出来),k=(h-b)/x=(h-H)/x(这个不用解释吧) 所以这条直线(也就是光线)与地面相交于y=0时 即x1=-b/k. 因为b,k已知,所以肯定求得出来 然后…
很简单的一题,注意墙上的影子是放大就行.用三分. #include <iostream> #include <cstdio> #include <cstring> #include <cmath> using namespace std; double H,h,D; double cal(double x){ return x+(h-x/D*H)*D/(D-x); } int main(){ double ans; int T; scanf("%d…