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,并给 ...
随机推荐
- Symfony2 是什么(转)
本文转自:http://www.cnblogs.com/Seekr/archive/2012/06/15/2550894.html Symfoy2 是什么? PHP世界里又一广受关注的web MVC框 ...
- C++中复制构造函数与重载赋值操作符
我们都知道,在C++中建立一个类,这个类中肯定会包括构造函数.析构函数.复制构造函数和重载赋值操作:即使在你没有明确定义的情况下,编译器也会给你生成这样的四个函数.例如以下类: class CTe ...
- kafak 命令使用
本篇文章主要内容: kafka常用命令总结 一.kafka常用命令总结: 1.创建topic bin/kafka-topics.sh --create --zookeeper ip:port/chro ...
- 郝斌老师C语言学习笔记(一)
在给变量分配内存时,很可能这段内存存在以前其他程序使用留下的值.当使用VC编译器,若编译器发现没有给变量赋值而使用,就会返回一个以“85”开头的很大的数字(此时该段内存中为一个垃圾数,为了避免出现较常 ...
- T-SQL表联接查询
由于实践不足,总是忘记SQL Server 联接表查询的细节,在这里记录以便查询. 一.交叉联接 交叉联接仅执行一个罗辑查询处理阶段——笛卡尔积.也就是说,将一个输入表的每一行与另一个表的所有行匹配. ...
- STL之优先队列(priority_queue)
转自网上大牛博客,原文地址:http://www.cnblogs.com/summerRQ/articles/2470130.html 先回顾队列的定义:队列(queue)维护了一组对象,进入队列的对 ...
- Matlab 矩阵运算
1.Syms 和sym的区别: syms是定义多个符号是符号变量的意思 sym只能定义一个符号变量,但可以具体到这个符号变量的内容 例:syms f z; %定义下x和y f=sym('a+b+c') ...
- C写的扫描器源码
Title:C写的扫描器源码 --2010-10-27 20:02 无意间看见的一个源代码,弄回来读下. ----------------------------------------------- ...
- NUnit+mock+moq单元测试
[TestFixture] public class InstantBatchBuyTest { private string _mallAbc; private string _itemCode; ...
- cf B. Fox Dividing Cheese
http://codeforces.com/contest/371/problem/B #include <cstdio> #include <iostream> #inclu ...