推公式/二分法


  好题!

  题解:http://blog.csdn.net/zck921031/article/details/7690288

  这题明显是一个方程组……可以推公式推出来……

  然而这太繁琐了!发现a[i]是满足单调性的话,我们就可以二分a[1],递推出a[n+1],进行验证……

  思维复杂度比推公式低到不知哪里去了,真是一种优秀的算法(然而我想不到,并没有什么*用……)

 Source Code
Problem: User: sdfzyhy
Memory: 736K Time: 16MS
Language: G++ Result: Accepted Source Code //PKUSC 2013 B
//POJ 2601
#include<vector>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;++i)
#define F(i,j,n) for(int i=j;i<=n;++i)
#define D(i,j,n) for(int i=j;i>=n;--i)
using namespace std;
typedef long long LL;
inline int getint(){
int r=,v=; char ch=getchar();
for(;!isdigit(ch);ch=getchar()) if (ch=='-') r=-;
for(; isdigit(ch);ch=getchar()) v=v*-''+ch;
return r*v;
}
const int N=;
const double eps=1e-;
/*******************template********************/ int n;
double a[N],c[N],ed;
inline double check(double x){
a[]=x;
F(i,,n+) a[i]=*(a[i-]+c[i-])-a[i-];
return a[n+];
}
int main(){
#ifndef ONLINE_JUDGE
freopen("B.in","r",stdin);
freopen("B.out","w",stdout);
#endif
scanf("%d%lf%lf",&n,&a[],&ed);
F(i,,n) scanf("%lf",&c[i]);
double l=-,r=,mid;
while(r-l>eps){
mid=(l+r)/;
if (check(mid)>ed) r=mid;
else l=mid;
}
printf("%.2f\n",l);
return ;
}
Simple calculations
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 6646   Accepted: 3322

Description

There is a sequence of n+2 elements a0, a1, ..., an+1 (n <= 3000, -1000 <= ai <=1000). It is known that ai = (ai-1 + ai+1)/2 - ci for each i=1, 2, ..., n.
You are given a0, an+1, c1, ... , cn. Write a program which calculates a1.

Input

The first line of an input contains an integer n. The next two lines consist of numbers a0 and an+1 each having two digits after decimal point, and the next n lines contain numbers ci (also with two digits after decimal point), one number per line.

Output

The output file should contain a1 in the same format as a0 and an+1.

Sample Input

1
50.50
25.50
10.15

Sample Output

27.85

Source

[Submit]   [Go Back]   [Status]   [Discuss]

【POJ】【2601】Simple calculations的更多相关文章

  1. 【 POJ - 1204 Word Puzzles】(Trie+爆搜|AC自动机)

    Word Puzzles Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 10782 Accepted: 4076 Special ...

  2. 【POJ 1459 power network】

    不可以理解的是,测评站上的0ms是怎么搞出来的. 这一题在建立超级源点和超级汇点后就变得温和可爱了.其实它本身就温和可爱.对比了能够找到的题解: (1)艾德蒙·卡普算法(2)迪尼克算法(3)改进版艾德 ...

  3. 【POJ 2728 Desert King】

    Time Limit: 3000MSMemory Limit: 65536K Total Submissions: 27109Accepted: 7527 Description David the ...

  4. 【POJ 2976 Dropping tests】

    Time Limit: 1000MSMemory Limit: 65536K Total Submissions: 13849Accepted: 4851 Description In a certa ...

  5. 【POJ 3080 Blue Jeans】

    Time Limit: 1000MSMemory Limit: 65536K Total Submissions: 19026Accepted: 8466 Description The Genogr ...

  6. 【POJ各种模板汇总】(写在逆风省选前)(不断更新中)

    1.POJ1258 水水的prim……不过poj上硬是没过,wikioi上的原题却过了 #include<cstring> #include<algorithm> #inclu ...

  7. 【POJ 3669 Meteor Shower】简单BFS

    流星雨撞击地球(平面直角坐标第一象限),问到达安全地带的最少时间. 对于每颗流星雨i,在ti时刻撞击(xi,yi)点,同时导致(xi,yi)和上下左右相邻的点在ti以后的时刻(包括t)不能再经过(被封 ...

  8. 【POJ 2823 Sliding Window】 单调队列

    题目大意:给n个数,一个长度为k(k<n)的闭区间从0滑动到n,求滑动中区间的最大值序列和最小值序列. 最大值和最小值是类似的,在此以最大值为例分析. 数据结构要求:能保存最多k个元素,快速取得 ...

  9. 【POJ 2406 Power Strings】

    Time Limit: 3000MSMemory Limit: 65536K Description Given two strings a and b we define a*b to be the ...

随机推荐

  1. sqoop的eval工具

    eval的作用:Evaluate a SQL statement and display the results,也就是说eval像是一个数据库的客户端工具. 一.使用eval来查询表 $ sqoop ...

  2. C++ string 转 char*

    string 转到 char* char name[20]; string sname=GatherName[n]; strcpy(name,sname.c_str());

  3. 黑白棋游戏 (codevs 2743)题解

    [问题描述] 黑白棋游戏的棋盘由4×4方格阵列构成.棋盘的每一方格中放有1枚棋子,共有8枚白棋子和8枚黑棋子.这16枚棋子的每一种放置方案都构成一个游戏状态.在棋盘上拥有1条公共边的2个方格称为相邻方 ...

  4. LaTeX让公式跟随章节编号

    正常公式编号会是(1)(2)这种,想要编号成(3.1) (3.2)怎么办呢? \usepackage{amsmath} \numberwithin{equation}{section} 在导言区加入以 ...

  5. 欢迎来到vmax-tam的博客

    欢迎来到vmax-tam的博客 我是一个新手程序员 以后会不断学习 把学到的东西记录下来 和大家一起分享的 谢谢大家指教

  6. linux动态库编译和使用详细剖析

    引言 重点讲述linux上使用gcc编译动态库的一些操作.并且对其深入的案例分析.最后介绍一下动态库插件技术, 让代码向后兼容.关于linux上使用gcc基础编译, 预编译,编译,生成机械码最后链接输 ...

  7. 解惑:NFC手机如何轻松读取银行卡信息?

    自支付宝钱包8.0推出了NFC新功能,只要将支持NFC功能的手机靠近公交卡.银行卡等带有芯片的IC卡上,可迅速读取卡内余额.卡的信息,还可以给卡进行充值,非常贴心实用. 但是很多网友表示担忧,要是别人 ...

  8. [原创]pg_shard使用场景及功能测试

    pg_shard是一个PostgreSQL的sharding extension.可以用于Shards.Replicates tables和高可用.它可以在不修改Applications的情况下无缝分 ...

  9. “猜你喜欢”是怎么猜中你心思的?

    文/Joseph A. Konstan & John Riedl)如今,到网上购物的人已经习惯了收到系统为他们做出的个性化推荐.Netflix 会推荐你可能会喜欢看的视频.TiVo 会自动把节 ...

  10. 浅谈HAL

    参考:http://blog.csdn.net/mr_raptor/article/details/8074549 代码实现:http://blog.csdn.net/mr_raptor/articl ...