UVA - 10014

Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu

id=19100" style="color:blue">Submit Status

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.

id=19100" style="color:blue">For each test case, the first line of an input file 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.

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 :: Prominent Problemsetters :: Alex Gevak

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 (经典的数学推导题!!)的更多相关文章

  1. uva 10014 Simple calculations

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  2. UVA 11300 Spreading the Wealth (数学推导 中位数)

    Spreading the Wealth Problem A Communist regime is trying to redistribute wealth in a village. They ...

  3. GCD - Extreme (II) UVA - 11426 欧拉函数_数学推导

    Code: #include<cstdio> using namespace std; const int maxn=4000005; const int R=4000002; const ...

  4. hdu 5430 Reflect (数学推导题)

    Problem Description We send a light from one point on a mirror material circle,it reflects N times a ...

  5. leetcode 343. Integer Break(dp或数学推导)

    Given a positive integer n, break it into the sum of at least two positive integers and maximize the ...

  6. 借One-Class-SVM回顾SMO在SVM中的数学推导--记录毕业论文5

    上篇记录了一些决策树算法,这篇是借OC-SVM填回SMO在SVM中的数学推导这个坑. 参考文献: http://research.microsoft.com/pubs/69644/tr-98-14.p ...

  7. 【POJ】【2601】Simple calculations

    推公式/二分法 好题! 题解:http://blog.csdn.net/zck921031/article/details/7690288 这题明显是一个方程组……可以推公式推出来…… 然而这太繁琐了 ...

  8. 关于不同进制数之间转换的数学推导【Written By KillerLegend】

    关于不同进制数之间转换的数学推导 涉及范围:正整数范围内二进制(Binary),八进制(Octonary),十进制(Decimal),十六进制(hexadecimal)之间的转换 数的进制有多种,比如 ...

  9. uva 12253 - Simple Encryption(dfs)

    题目链接:uva 12253 - Simple Encryption 题目大意:给定K1.求一个12位的K2,使得KK21=K2%1012 解题思路:按位枚举,不且借用用高速幂取模推断结果. #inc ...

随机推荐

  1. Zygote过程【3】——SystemServer诞生

    欢迎转载.转载请注明:http://blog.csdn.net/zhgxhuaa 在ZygoteInit的main()方法中做了几件大事.当中一件便是启动Systemserver进程.代码例如以下: ...

  2. Python爬虫(一)

    花了四天的时间用python写了个简单的爬虫程序.整个过程分为两个部分:工具的安装和程序的实现 本文并没有讲程序的详细实现遇到的问题,而是对着手前一些前期的准备 第一部分(工具的安装) 开发工具的下载 ...

  3. java提高篇(十一)-----代码块

    在编程过程中我们可能会遇到如下这种形式的程序: public class Test { { //// } } 这种形式的程序段我们将其称之为代码块,所谓代码块就是用大括号({})将多行代码封装在一起, ...

  4. Apple Watch 1.0 开发介绍 1.4 简介 使用iOS技术

    WatchKit extension可以使用iOS app同样的技术,但是由于他是extension,使用有些技术的时候会有限制,有些不推荐使用.下面是一些介绍以及什么时候使用什么技术: 有些需要权限 ...

  5. 综合第一篇文章(带钩Quora)

    watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxNDc4MzAyNw==/font/5a6L5L2T/fontsize/400/fill/I0JBQk ...

  6. [原创].NET 分布式架构开发实战之二 草稿设计

    原文:[原创].NET 分布式架构开发实战之二 草稿设计 .NET 分布式架构开发实战之二 草稿设计 前言:本篇之所以称为草稿设计,是因为设计的都是在纸上完成的.反映了一个思考的过程. 本篇的议题如下 ...

  7. S2SH新手框架结构的准备工作只需要导入这些文件

    实习北京最近一直在某公司.时间很冲突,总想着有事找东西坐,思想,做事先成套我吧 一套完整的东西想好主题,术去实现了,在学校尽管说是学了J2EE,可是确实没学到东西,Struts2+Hibernate不 ...

  8. RPG游戏学习——1.任务脚本系统

    [前言] 近期准备做个rpg小游戏,所以開始研究rpg的一些系统.rpg最核心的应该是任务脚本系统(其它脚本系统类似),在參考了非常多网上的资料后,简要总结例如以下. [脚本的触发运行] 一个脚本须要 ...

  9. [Linux]于Mac在配置Linuxserver安装Nginx+PHP

    Linux 安装Debian系统 我安装的是Debian7.5的系统,Debian的软件包管理和升级十分方便,并且系统也非常稳定. 安装盘能够去华中科技大学镜像.网易开源镜像站或者中国科技大学镜像下载 ...

  10. 使用EasyUI实现加入和删除功能

    增删该查是不论什么一个项目都少不了的功能操作.这篇博文主要简单介绍一下怎样使用EasyUI实现加入和删除功能. 首先.导入EasyUI的js代码: <link href="~/Easy ...