POJ 1759 Garland(二分+数学递归+坑精度)
这个题wa了27次,忘了用一个数来储存f[n-1],每次由于二分都会改变f[n-1]的值,得到的有的值不精确,直接输出f[n-1]肯定有问题.
这个题用c++交可以过,g++交过不了,
f[i]=2+2*f[i-1]-f[i-2]; f[0]=A,f[1]=x;
二分枚举x的值,最终得到B的值(不是f[n-1]),
上述递推式是非齐次的二阶递推式,解其齐次特征方程,可以得到f[n-1]的齐次时的表达式,对于非齐次的,目前我还没法求出通式,
B与f[n-1]的关系不好确定
B的值应该与f[1]的值成正相关,但是不知道怎么证明,如果不是正相关,则二分枚举有问题.
/*
* Created: 2016年04月03日 17时02分06秒 星期日
* Author: Akrusher
*
*/
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <fstream>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define in(n) scanf("%d",&(n))
#define in2(x1,x2) scanf("%d%d",&(x1),&(x2))
#define in3(x1,x2,x3) scanf("%d%d%d",&(x1),&(x2),&(x3))
#define inll(n) scanf("%I64d",&(n))
#define inll2(x1,x2) scanf("%I64d%I64d",&(x1),&(x2))
#define inlld(n) scanf("%lld",&(n))
#define inlld2(x1,x2) scanf("%lld%lld",&(x1),&(x2))
#define inf(n) scanf("%f",&(n))
#define inf2(x1,x2) scanf("%f%f",&(x1),&(x2))
#define inlf(n) scanf("%lf",&(n))
#define inlf2(x1,x2) scanf("%lf%lf",&(x1),&(x2))
#define inc(str) scanf("%c",&(str))
#define ins(str) scanf("%s",(str))
#define out(x) printf("%d\n",(x))
#define out2(x1,x2) printf("%d %d\n",(x1),(x2))
#define outf(x) printf("%f\n",(x))
#define outlf(x) printf("%lf\n",(x))
#define outlf2(x1,x2) printf("%lf %lf\n",(x1),(x2));
#define outll(x) printf("%I64d\n",(x))
#define outlld(x) printf("%lld\n",(x))
#define outc(str) printf("%c\n",(str))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define mem(X,Y) memset(X,Y,sizeof(X));
typedef vector<int> vec;
typedef long long ll;
typedef pair<int,int> P;
const int dx[]={,,-,},dy[]={,,,-};
const int INF=0x3f3f3f3f;
const ll mod=1e9+;
ll powmod(ll a,ll b) {ll res=;a%=mod;for(;b;b>>=){if(b&)res=res*a%mod;a=a*a%mod;}return res;}
const bool AC=true; int n;
double f[],b;
bool C(double x){
f[]=x;
rep(i,,n){
f[i]=+*f[i-]-f[i-];
if(f[i]<) return false;
}
b=f[n-]; //一定要找个数来储存正确的f[n-1],否则会wa
return true;
}
int main()
{
double lb,ub,mid;
in(n);
inlf(f[]);
lb=,ub=;
rep(i,,){
mid=(ub+lb)/;
if(C(mid)) ub=mid;
else lb=mid;
}
printf("%.2lf",b);
return ;
}
循环100次,交上去耗时是16ms,循环30次,交上去是0ms
POJ 1759 Garland(二分+数学递归+坑精度)的更多相关文章
- 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
Garland Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 2365 Accepted: 1007 Descripti ...
- poj 1759 Garland (二分搜索之其他)
Description The New Year garland consists of N lamps attached to a common wire that hangs down on th ...
- POJ1759 Garland —— 二分
题目链接:http://poj.org/problem?id=1759 Garland Time Limit: 1000MS Memory Limit: 10000K Total Submissi ...
- poj 2049(二分+spfa判负环)
poj 2049(二分+spfa判负环) 给你一堆字符串,若字符串x的后两个字符和y的前两个字符相连,那么x可向y连边.问字符串环的平均最小值是多少.1 ≤ n ≤ 100000,有多组数据. 首先根 ...
- poj 2318 叉积+二分
TOYS Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 13262 Accepted: 6412 Description ...
- POJ - 1191 棋盘分割 记忆递归 搜索dp+数学
http://poj.org/problem?id=1191 题意:中文题. 题解: 1.关于切割的模拟,用递归 有这样的递归方程(dp方程):f(n,棋盘)=f(n-1,待割的棋盘)+f(1,割下的 ...
- 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(二分)
传送门:Problem 1759 https://www.cnblogs.com/violet-acmer/p/9793209.html 题意: 有N个彩灯关在同一条绳上,给出第一个彩灯的高度A,并给 ...
随机推荐
- 《python基础教程》笔记之 其它语句1
print 相关 print可以打印多个表达式,只要将它们用逗号隔开就好,结果中每个参数之间都会插入一个空格,使用+可以避免空格,如 >>> print 'age:',42age: ...
- OpenStack JEOS 镜像
JEOS:Just Enough Operating System 维基百科地址:http://en.wikipedia.org/wiki/Just_enough_operating_system O ...
- CallableStatement执行存储过程
/** * 使用CablleStatement调用存储过程 * @author APPle * */ public class Demo1 { /** * 调用带有输入参数的存储过程 * CALL p ...
- iOS APP安全杂谈
iOS APP安全杂谈 高小厨 · 2015/06/30 10:16 0x00 序 以前总是在这里看到各位大牛分享其安全渗透经验,而今我也很荣幸的收到了乌云的约稿,兴奋之情难以言表.由于IOS是一 ...
- iOS网络编程-ASIHTTPRequest框架同步请求-备用
在ASIHTTPRequest框架中与HTTP请求相关的类有:ASIHTTPRequest和ASIFormDataRequest,其中最常用的是ASIHTTPRequest,ASIFormDataRe ...
- 05 - 替换vtkDataObject中的Update方法 VTK 6.0 迁移
VTK6 引入了许多不兼容的变.其中之一是删除vtkDataObject中所有有关管道的方法.下面讨论update方法并提供迁移现有代码的建议. Update() vtkDataObject::Upd ...
- android中如何处理cookie
Managing Cookies HttpClient provides cookie management features that can be particularly useful to t ...
- css 选择器 (学习笔记)
参考 http://zachary-guo.iteye.com/blog/605116 1. div+p 选择紧接在 <div> 元素之后的所有 <p> 元素.解释 : fi ...
- 王学长的AAA树
让我们响应王学长的号召勇敢的分开写splay和lct吧! 分开写大法好!!!!!!!!!!!杜教的ch[4]弱爆了!!!! #include <stdio.h> #include < ...
- bzoj2821作诗
http://www.lydsy.com/JudgeOnline/problem.php?id=2821 分块 我们把数列分成$\sqrt{N}$块 记$f[i][j]$表示第i块到第j块的答案,这个 ...