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 ...
随机推荐
- Hadoop学问Eclipse构建Hadoop工程
在此之前的基础Hadoop在官方文件HDFS.MapReduce架构.配置管理是学习,但是,一些地方的官方文件相当含糊的解释. 我们没有发挥人可以体验,某种官方文件似业务规则或要求,但是,真正的细节还 ...
- 二叉查找树C语言实现
二叉查找树C语言实现 1. 二叉查找树的定义: 左子树不为空的时候,左子树的结点值小于根节点,右子树不为空时,右子树的结点值大于根节点,左右子树分别为二叉查找树 2. 二叉查找树的 ...
- 使用commons-fileupload进行上传
须要使用的包 这两个包在Apache官网上能够下载得到 commons-fileupload-1.3.1.jar是Apache的一个开源项目.废话不说直接说吧 前段页面 <form action ...
- c++ stl algorithm: std::find, std::find_if
std::find: 查找容器元素, find仅仅能查找容器元素为<基本数据类型> [cpp] view plaincopy #include <iostream> #incl ...
- 用AsyncTask实现多线程
前言 在Android应用开发中,有时我们需要实现任务的同步.Android里的AsyncTask类可以帮我们更好地管理线程同步(异步方式),就像Thread类能做的,不过用法比Thread更简单. ...
- 实现DataGridView行的拖动,即实现行的顺序交换
参考:http://blog.csdn.net/soarheaven/article/details/3267379 1.界面准备 (1)首先在form中添加一个DataGridView控件,将默认A ...
- Socket规划中的局域网内测试
前面提到的Socket信息及文件传输软件,如何测试和使用它? 事实上仅仅要推断client及server的局域网连通就可以. 1.Server在cmd下输入 ipconfig/all获得IP地址或者本 ...
- 电脑知识--Windows一片
.com档 Dos可执行命令文件,一般小于64kb, .com文件包括程序的一个绝对映像.就是说,为了执行程序准确的处理器指令和内存中的数据.Ms-Dos通过直接把该映像从文件复制到内存. 而 载入. ...
- newlisp 接受jenkins带空格的参数
jenkins有一个参数text种类,它能够以文本的段落拷贝作为参数 newlispThe program receives parameters are separated by spaces, 更 ...
- Linux学习笔记——如何使用共享库交叉编译
0.前言 在较为复杂的项目中会利用到交叉编译得到的共享库(*.so文件).在这样的情况下便会产生下面疑问,比如: [1]交叉编译时的共享库是否须要放置于目标板中,假设须要放置在哪个文件 ...