Simple calculations
Description
有一个包括n+2个元素的数列a0, a1, ..., an+1 (n <= 3000, -1000 <= ai <=1000)。它们之间满足ai = (ai-1 + ai+1)/2 - ci (i=1, 2, ..., n)。如今给出a0, an+1, c1, ... , cn.。请编敲代码计算出a1。
Input
输入的第一行是一个整数n。
接下去的两行各自是a0和an+1,(精确到小数点后两位)再接下去的n行是ci(精确到小数点后两位)。每一个数字占一行。
Output
输出a1 ,其格式与 a0 同样。
Sample Input
1
50.50
25.50
10.15
Sample Output
27.85
接下去的两行各自是a0和an+1,(精确到小数点后两位)再接下去的n行是ci(精确到小数点后两位)。每一个数字占一行。
50.50
25.50
10.15
解题思路:
a[1] + a[2] = a[0] + a[3] - 2 * (c[1] + c[2])
a[1] + a[n] = a[0] + a[n+1] - 2 * (c[1] + ... + c[n])
等式两边分别相加后得:
(n + 1) * a[1] = n * a[0] + a[n+1] - 2 * (c[1] + (c[1] + c[2]) + ... + (c[1] + c[2] + ... +c[n]))
#include<stdio.h>
#define MAX_NUM 3005
int main()
{
double a[MAX_NUM], c[MAX_NUM];
int n;
scanf("%d", &n);
scanf("%lf%lf", &a[0], &a[n+1]);
for(int i = 1; i <= n; i++)
scanf("%lf", &c[i]);
int j = 1;
double sum_1 = 0, sum_2 = 0;
for(int i = 1; i <= n ; i++)
{
for(; j <= i; j++)
{
sum_1 += c[j];
}
sum_2 += sum_1;
}
a[1] = (n * a[0] + a[n + 1] - 2 * sum_2) / (n + 1);
printf("%.2lf\n", a[1]);
return 0;
}
Simple calculations的更多相关文章
- 【POJ】【2601】Simple calculations
推公式/二分法 好题! 题解:http://blog.csdn.net/zck921031/article/details/7690288 这题明显是一个方程组……可以推公式推出来…… 然而这太繁琐了 ...
- UVA - 10014 - Simple calculations (经典的数学推导题!!)
UVA - 10014 Simple calculations Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & ...
- poj 2601 Simple calculations
Simple calculations Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6559 Accepted: 32 ...
- uva 10014 Simple calculations
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- UVa10820 Send a Table[欧拉函数]
Send a TableInput: Standard Input Output: Standard Output When participating in programming contests ...
- UVA题目分类
题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...
- Working with Data » Getting started with ASP.NET Core and Entity Framework Core using Visual Studio » 排序、筛选、分页以及分组
Sorting, filtering, paging, and grouping 7 of 8 people found this helpful By Tom Dykstra The Contoso ...
- UVA 10820 - Send a Table 数论 (欧拉函数)
Send a Table Input: Standard Input Output: Standard Output When participating in programming contest ...
- uva 10820 (筛法构造欧拉函数)
send a table When participating in programming contests, you sometimes face the following problem: Y ...
随机推荐
- Ubuntu14.04使用root登陆帐户
http://jingyan.baidu.com/article/27fa73268144f346f8271f83.html 1.输入sudo gedit /usr/share/lightdm/lig ...
- xfce-openvas9
1安装OpenVas 第一步,添加PPA源,在这我用的是一台新装的Ubuntu安装OpenVas,运行以下命令就可以进行安装 root@ubuntu:~# add-apt-repository ppa ...
- 10大vim插件
Taglist taglist是一个用于显示定位程序中各种符号的插件,例如宏定义.变量名.结构名.函数名这些东西 我们将其称之为符号(symbols),而在taglist中将其称之为tag.显然,要想 ...
- iRule Event Order - HTTPSv7
v
- 【Luogu】P2258子矩阵(状态压缩,DP)
233今天蒟蒻我连文化课都没听光想着这个了 然后我调了一下午终于过了!!! 一看数据范围似乎是状压,然而216等于65536.开一个65536*65536的二维数组似乎不太现实. 所以Rqy在四月还是 ...
- 二分图最小覆盖的Konig定理及其证明,最小的覆盖证明
[转http://www.cppblog.com/abilitytao/archive/2009/09/02/95147.html -> http://yejingx.ycool.com/p ...
- net2:类,事件与委托
原文发布时间为:2008-07-29 -- 来源于本人的百度文章 [由搬家工具导入] using System;using System.Data;using System.Configuration ...
- 同时在windows和linux环境开发时换行符的处理
Git 的 core.autocrlf 參數默认为true,即每次 checkin 時,Git 會將純文字類型的檔案中的所有 CRLF 字元轉換為 LF,也就是版本庫中的換行符號一律存成 LF:在 c ...
- Windows Phone 8.1 开发实例 网络编程 天气预报
首先感谢林政老师的博客,给了我很大的指导. 准备工作 我的开发环境: - Visual Studio 2013(With Update 4) - Windows Phone 8.1 - Windows ...
- 【Java TCP/IP Socket】TCP Socket(含代码)
TCP的Java支持 协议相当于相互通信的程序间达成的一种约定,它规定了分组报文的结构.交换方式.包含的意义以及怎样对报文所包含的信息进行解析,TCP/IP协议族有IP协议.TCP协议和UDP协议.现 ...