推公式/二分法


  好题!

  题解: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. php异常处理示例

    php异常处理使用示例,代码说明了普通错误和致命错误捕获及处理的方法.  代码如下: <?php //禁止错误输出 error_reporting(0); //设置错误处理器 set_error ...

  2. 通过bind实现activity与service的交互

    先点bind按钮实现onCreate,在点击start给service传值(get方法) xml: <RelativeLayout xmlns:android="http://sche ...

  3. Java 第五天 Spring IOC 配置文件

    Spring xml结构定义文件: http://www.springframework.org/schema/beans/spring-beans.xsd 可用xsd列表: http://www.s ...

  4. python杂记-1(os模块)

    os模块说明:python os模块包含普遍的操作系统功能 os.access(path, mode) # 检验权限模式 os.chdir(path) # 改变当前工作目录os.chflags(pat ...

  5. 编译android程序时DEX过程出现错误

    今天编译高级设置时出现了错误,这好坑爹啊~ 于是我开始检查代码,发现代码没有错误啊,然后观察MAKE的步骤才发现是DEX时出现了问题!! 下面是错误的LOG: Information:Using ja ...

  6. [笔记]--Sublime Text 2使用技巧

    Sublime个人喜好设置: 在打开个人设置页面Preferences >> Settings - User,加入以下内容: { , //TAB键,4个空格 "translate ...

  7. JavaWeb之Servlet:请求 与 响应

    1 引入 浏览器和服务器的种类都有很多,要在它们之间通讯,必定要遵循一定的准则,而http协议就是这样的一个"准则". Http协议:规定了 浏览器 和 服务器 数据传输的一种格式 ...

  8. hdu 4593 Robot

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4593 Robot Description A robot is a mechanical or vir ...

  9. hdu 5233 Gunner II

    原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=5233 简单题,stl水之... #include<algorithm> #include& ...

  10. ubuntu server获取并自动设置最快镜像的方法

    一,安装方法1 add-apt-repository ppa:ossug-hychen/getfastmirrorapt-get install getfastmirror 如果添加了临时源,这样移除 ...