UVA - 10014 - Simple calculations (经典的数学推导题!!)
UVA - 10014
| Time Limit: 3000MS | Memory Limit: Unknown | 64bit IO Format: %lld & %llu |
id=19100" style="color:blue">Submit
Description
id=19100" style="color:blue">The Problem
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.
The Input
id=19100" style="color:blue">The first line is the number of test cases, followed by a blank line.
Each test case will be separated by a single line.
The Output
For each test case, the output file should contain a1 in the same format as a0 and an+1.
id=19100" style="color:blue">Print a blank line between the outputs for two consecutive test cases.
Sample Input
1
1
50.50
25.50
10.15
Sample Output
27.85
Source
Root :: Competitive Programming 3: The New Lower Bound of Programming Contests (Steven & Felix Halim) :: Mathematics :: Ad Hoc Mathematics Problems :: Finding
Pattern or Formula, easier
Root :: Competitive Programming 2: This increases the lower bound of Programming Contests. Again (Steven & Felix Halim) :: Mathematics :: Ad Hoc Mathematics Problems ::
option=com_onlinejudge&Itemid=8&category=395" style="color:blue">Finding
Pattern or Formula
Root :: AOAPC I: Beginning Algorithm Contests (Rujia Liu) :: Volume 1. Elementary Problem Solving :: Maths - Misc
非常经典的数学推导题!!
!
首先。依据题意有a[i] = (a[i-1] + a[i+1]) / 2 - c[i];
变换可得a[i+1] = (a[i] + c[i]) * 2 - a[i-1];
则a[n+1] = (a[n] + c[n]) * 2 -a[n-1]
= [ ( a[n-1] + c[n-1] ) * 2 - a[n-2] + c[n] ] * 2 - a[ n-1]
= 3*a[n-1] - 2*a[n-2] + 4*c[n-1] + 2*c[n]
= 4*a[n-2] - 3*a[n-3] + 6*c[n-2] + 4*c[n-1] + 2*c[n]
= 5*a[n-3] -
4*a[n-4] +
8*c[n-3] + 6*c[n-2] + 4*c[n-1] + 2*c[n]
....
= (n+1)*a[1] - n *a[0] + (n+1 - i) * 2 * c[i] + ....
则 a[1] * (n+1)= a[n+1] + n*a[0] - (n+1-i)*2*c[i] + .....
手敲果然慢......
AC代码:
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <string>
using namespace std; const int maxn = 3005; int main()
{
int cas;
scanf("%d", &cas);
while(cas--)
{
int n;
scanf("%d", &n);
double a0, am, c[maxn];
scanf("%lf %lf", &a0, &am);
double ans = a0*n + am;
for(int i=1; i<=n; i++)
{
scanf("%lf", &c[i]);
ans -= (n+1-i)*c[i]*2;
}
printf("%.2lf\n", ans/(n+1));
if(cas!=0)printf("\n");
}
return 0;
}
版权声明:本文博客原创文章,博客,未经同意,不得转载。
UVA - 10014 - Simple calculations (经典的数学推导题!!)的更多相关文章
- uva 10014 Simple calculations
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- UVA 11300 Spreading the Wealth (数学推导 中位数)
Spreading the Wealth Problem A Communist regime is trying to redistribute wealth in a village. They ...
- GCD - Extreme (II) UVA - 11426 欧拉函数_数学推导
Code: #include<cstdio> using namespace std; const int maxn=4000005; const int R=4000002; const ...
- hdu 5430 Reflect (数学推导题)
Problem Description We send a light from one point on a mirror material circle,it reflects N times a ...
- leetcode 343. Integer Break(dp或数学推导)
Given a positive integer n, break it into the sum of at least two positive integers and maximize the ...
- 借One-Class-SVM回顾SMO在SVM中的数学推导--记录毕业论文5
上篇记录了一些决策树算法,这篇是借OC-SVM填回SMO在SVM中的数学推导这个坑. 参考文献: http://research.microsoft.com/pubs/69644/tr-98-14.p ...
- 【POJ】【2601】Simple calculations
推公式/二分法 好题! 题解:http://blog.csdn.net/zck921031/article/details/7690288 这题明显是一个方程组……可以推公式推出来…… 然而这太繁琐了 ...
- 关于不同进制数之间转换的数学推导【Written By KillerLegend】
关于不同进制数之间转换的数学推导 涉及范围:正整数范围内二进制(Binary),八进制(Octonary),十进制(Decimal),十六进制(hexadecimal)之间的转换 数的进制有多种,比如 ...
- uva 12253 - Simple Encryption(dfs)
题目链接:uva 12253 - Simple Encryption 题目大意:给定K1.求一个12位的K2,使得KK21=K2%1012 解题思路:按位枚举,不且借用用高速幂取模推断结果. #inc ...
随机推荐
- 程序员---C语言细节7(增加两个整数溢出检测)
主要内容:增加两个整数溢出检测 #include <stdio.h> #include <limits.h> int main(int argc, char *argv[]) ...
- 玩转Web之easyui(三)-----easy ui dataGird 重新指定url以获取不同数据源信息
如果已经写了一个dataGird并且已经通过url绑定数据源,能不能在其他地方改变url使其从不同数据源获取信息,从而实现查询等操作?答案当然是肯定的,而且仅需要几行代码 $('#btnq').bin ...
- Convert View To Bitmap
public static Bitmap convertViewToBitmap(View view) { view.destroyDrawingCache(); view.measure(View. ...
- MY WAY程序(十三) 理念和技术
背部,该项目团队去了一半多,我们出差.我将离开之前,闪亮强哥给了我学习技术的列表,以了解它:AngularJs,bootsrap,smartadmin,html5,css3.很多前景的技术.哎,学吧, ...
- unity简易小地图的实现(NGUI)
首先,我们在场景中添加一个摄像机叫做minimapCamera, 把上面的Audio Listener组件去掉,调整摄像机位置,将其置于角色正上方,如图 新建一个Texture我们叫做minimapT ...
- HDU4540+DP
简单题... dp[ i ][ j ] 表示第 i 行取第 j 个数的MinVal /* DP&简单题 */ #include<stdio.h> #include<strin ...
- 7 JavaScript Basics Many Developers Aren't Using (Properly)【转】
JavaScript, at its base, is a simple language that we continue to evolve with intelligent, flexible ...
- 关于“类不能支持Automation操作”错误的解决方法
一段程序IE上老是提示“类不支持Automation操作”的错误,IE6.7.8都一样,但是Firefox可以,后来网上找到如下解决方法: 重新注册下以下文件,问题便解决了:msscript.ocxd ...
- 第十二章——SQLServer统计信息(1)——创建和更新统计信息
原文:第十二章--SQLServer统计信息(1)--创建和更新统计信息 简介: 查询的统计信息: 目前为止,已经介绍了选择索引.维护索引.如果有合适的索引并实时更新统计信息,那么优化器会选择有用的索 ...
- SUPPORTDIR引用的文件的加入
上一篇转载了SUPPORTDIR的理论解释,如今截图说明实际操作: 选择依赖的语言,在右面的files框里右键点击,选择Insert Files插入文件,编译.由于安装得时候,压缩包会解压成一个暂时文 ...