poj 1759 Garland
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 2365 | Accepted: 1007 |
Description
The New Year garland consists of N lamps attached to a common wire that hangs down on the ends to which outermost lamps are affixed. The wire sags under the weight of lamp in a particular way: each lamp is hanging at the height that is 1 millimeter lower than the average height of the two adjacent lamps.
The leftmost lamp in hanging at the height of A millimeters above the ground. You have to determine the lowest height B of the rightmost lamp so that no lamp in the garland lies on the ground though some of them may touch the ground.
You shall neglect the lamp's size in this problem. By numbering the lamps with integers from 1 to N and denoting the ith lamp height in millimeters as Hi we derive the following equations:
H1 = A
Hi = (Hi-1 + Hi+1)/2 - 1, for all 1 < i < N
HN = B
Hi >= 0, for all 1 <= i <= N
The sample garland with 8 lamps that is shown on the picture has A = 15 and B = 9.75.
Input
Output
Sample Input
692 532.81
Sample Output
446113.34
Source
/*
* @Author: Lyucheng
* @Date: 2017-07-25 10:07:16
* @Last Modified by: Lyucheng
* @Last Modified time: 2017-07-29 19:25:29
*/
/*
题意:有一串项链,给出第一个珠子的位置,然后保证每个珠子不能掉到地上,也就是说高度必须大于等于零,让你求最后一个珠子的位置 思路:二分答案就可以,判断条件可以推出公式
H1=A
H2=A/2 + H3/2 - 1
H3=A/3 + (H4*2)/3 - 2
...
Hn-1=A/(n-1) + (Hn*n-2)/n-1 - (n-2)
然后逆向推过来 错误:上面的公式可能存在损失精度的问题...可是打印了所有答案,真的没错...poj C++能过,但是G++就过不了 改进:H[i] = 2 * H[i - 1] + 2 - H[i - 2]; 还有个问题,用printf输出就不行,用cout输出就可以
*/ #include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
#include <iomanip> #define MAXL -1
#define MAXR 1000+16
#define MAXN 1000+16
#define EXP 1e-9 using namespace std; int n;
double A,B;
double F[MAXN]; bool ok(const double &x){
F[]=x;
for(int i=;i<=n;i++){
F[i]=*F[i-]+-F[i-];
if(F[i]<) return false;
}
B=F[n];
return true;
} int main(){
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
cin>>n>>A;
F[]=A;
double l=MAXL,r=MAXR,mid;
for(int i=;i<;i++){
mid=(l+r)/2.0;
if(ok(mid)==true){
r=mid;
}else{
l=mid;
}
}
cout << fixed << setprecision() << B << endl;
return ;
}
poj 1759 Garland的更多相关文章
- POJ 1759 Garland(二分+数学递归+坑精度)
POJ 1759 Garland 这个题wa了27次,忘了用一个数来储存f[n-1],每次由于二分都会改变f[n-1]的值,得到的有的值不精确,直接输出f[n-1]肯定有问题. 这个题用c++交可以 ...
- POJ 1759 Garland(二分答案)
[题目链接] http://poj.org/problem?id=1759 [题目大意] 有n个数字H,H[i]=(H[i-1]+H[i+1])/2-1,已知H[1],求最大H[n], 使得所有的H均 ...
- poj 1759 Garland (二分搜索之其他)
Description The New Year garland consists of N lamps attached to a common wire that hangs down on th ...
- Divide and conquer:Garland(POJ 1759)
挂彩灯 题目大意:就是要布场的时候需要挂彩灯,彩灯挂的高度满足: H1 = A Hi = (Hi-1 + Hi+1)/2 - 1, for all 1 < i < N HN = B Hi ...
- POJ 1759
Garland Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 1236 Accepted: 547 Descriptio ...
- poj 1759(二分)
传送门:Problem 1759 https://www.cnblogs.com/violet-acmer/p/9793209.html 题意: 有N个彩灯关在同一条绳上,给出第一个彩灯的高度A,并给 ...
- poj 1759 二分搜索
题意:N个等差数列,初项X_i,末项Y_i,公差Z_i,求出现奇数次的数? 思路: 因为只有一个数出现的次数为奇数个 假设 第二个数字的个数为 奇数个,其余全部都是偶数个 ,累计出现的次数 a1偶数 ...
- ProgrammingContestChallengeBook
POJ 1852 Ants POJ 2386 Lake Counting POJ 1979 Red and Black AOJ 0118 Property Distribution AOJ 0333 ...
- POJ 1064 1759 3484 3061 (二分搜索)
POJ 1064 题意 有N条绳子,它们长度分别为Li.如果从它们中切割出K条长度相同的绳子的话,这K条绳子每条最长能有多长?答案保留小数点后2位. 思路 二分搜索.这里要注意精度问题,代码中有详细说 ...
随机推荐
- 【DDD】领域驱动设计实践 —— UI层实现
前面几篇blog主要介绍了DDD落地架构及业务建模战术,后续几篇blog会在此基础上,讲解具体的架构实现,通过完整代码demo的形式,更好地将DDD的落地方案呈现出来.本文是架构实现讲解的第一篇,主要 ...
- Codeforces Round #436 (Div. 2) C. Bus
http://codeforces.com/contest/864/problem/C 题意: 坐标轴上有x = 0和 x = a两点,汽车从0到a之后掉头返回,从a到0之后又掉头驶向a...从0到a ...
- express 安装和运行
1.npm install -g express-generator 2.进入服务目录(自己定义的文件夹,或者express Myapp && cd Myapp 新建Myapp文件夹并 ...
- The Nerd Factor SPOJ - MYQ5
The Nerd Factor Time Limit: 1000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu [Submi ...
- Codeforces Round #425 (Div. 2)C
题目连接:http://codeforces.com/contest/832/problem/C C. Strange Radiation time limit per test 3 seconds ...
- vue-resource传参数到后端,后端取不到数据的问题
先上一段代码: this.$http.post('xxx',{Search_Text:this.search_text}).then(function(response){ // 响应成功回调 thi ...
- sql sever 基础知识及详细笔记
第六章:程序数据集散地:数据库 6.1:当今最常用的数据库 sql server:是微软公司的产品 oracle:是甲骨文公司的产品 DB2:数据核心又称DB2通用服务器 Mysql:是一种开发源代 ...
- 简单Elixir游戏服设计-创建玩家模型
删除model.ex 创建玩家模型 player.ex, 简单化,只有唯一标识,昵称,金币,够用了. 选择 map 代表数据,是为了扩展数据结构,方便增加功能.struct也是可以的. add_num ...
- 【vue系列之二】详解vue-cli 2.0配置文件
上次给大家分享的是用vue-cli快速搭建vue项目,虽然很省时间和精力,但想要真正搞明白,我们还需要对其原理一探究竟. 大家拿到一个项目,要快速上手,正确的思路是这样的: 首先,如果在项目有read ...
- jQuery扩展easyui.datagrid,添加数据loading遮罩效果代码
//jquery.datagrid 扩展加载数据Loading效果 (function (){ $.extend($.fn.datagrid.methods, { //显示遮罩 loading: fu ...