poj 2601 Simple calculations
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 6559 | Accepted: 3291 |
Description
n.
You are given a0, an+1, c1, ... , cn. Write a program which calculates a1.
Input
one number per line.
Output
Sample Input
1
50.50
25.50
10.15
Sample Output
27.85
解题思路:
大概过程:
a[0]+a[2]-2a[1]-2c[1]=0
a[1]+a[3]-2a[2]-2c[2]=0
……
a[n-1] + a[n+1] - 2a[n] - 2c[n] = 0
累加可得:
a[0]+a[n+1]-a[1]-a[n]-2c[1]-2c[2]-...-2c[n]=0
依据a[n-1]+a[n+1]-2a[n]-2c[n]=0 => a[n+1]-2c[n]-a[n]=a[n]+2c[n]-a[n-1]
化简:a[0]+a[n]-a[1]-a[n-1]-2c[1]-2c[2]-...-2c[n-1]=0
同理:a[0]+a[n-1]-a[1]-a[n-2]-2c[1]-2c[2]-...-2c[n-2]=0
……
a[0]+a[2]-a[1]-a[1]-2c[1]=0
相加上面各式可得n*a[0]+a[n+1]-(n+1)*a[1]-2*n*c[1]-2*(n-1)*c[2]-...-2*c[n]=0
即a[1]=(n*a[0]+a[n+1]-2*n*c[1]-2*(n-1)*c[2]-...-2*c[n])/(n+1)
#include <iostream>
#include <iomanip>
using namespace std;
#define MAX 3005
int main(){
int n;
double a0,an;
double c[MAX];
while (cin>>n){
cin>>a0>>an;
double ans=0;
for (int i=0;i<n;i++){
cin>>c[i];
ans+=2*(n-i)*c[i];
}
ans=(n*a0+an-ans)/(n+1);
cout<<fixed<<setprecision(2)<<ans<<endl;
}
return 0;
}
poj 2601 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 3468-A Simple Problem with Integers 线段树,树状数组
题目:http://poj.org/problem?id=3468 A Simple Problem with Integers Time Limit: 5000MS Memory Limit ...
- POJ A Simple Problem with Integers 线段树 lazy-target 区间跟新
A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 105742 ...
- POJ 3468A Simple Problem with Integers(线段树区间更新)
A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 112228 ...
- POJ 3922A Simple Stone Game
题目链接 A Sample Stone Game 题目大意:给定n,k,表示最初时有n个石头,两个人玩取石子游戏,第一个人第一次可以取1~n-1个石头,后面每个人最多可以拿走前面一个人拿走的个数的K倍 ...
- uva 10014 Simple calculations
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- POJ 2601
#include<iostream> #include<iomanip> #include<stdio.h> using namespace std; int ma ...
- POJ - 3468A Simple Problem with Integers (线段树区间更新,区间查询和)
You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type of op ...
随机推荐
- 几何+暴力【p1959】 遗址[NOI导刊2009普及(6)]
题目描述--> P1959 遗址_NOI导刊2009普及(6) 普通方法分析: 因为题目要求是找最大正方形(如果是长方形更麻烦. 讲真,题目不难,耗时间! 根据题目要求,我们要找的是正方形. 我 ...
- Combination Sum IV -- LeetCode
Given an integer array with all positive numbers and no duplicates, find the number of possible comb ...
- 【最近公共祖先】【线段树】URAL - 2109 - Tourism on Mars
Few people know, but a long time ago a developed state existed on Mars. It consisted of n cities, nu ...
- 【莫队算法】【权值分块】bzoj2223 [Coci 2009]PATULJCI
不带修改主席树裸题<=>莫队+权值分块裸题. 复杂度O(m*sqrt(n)). P.S.题目描述坑爹,第二个数是权值的范围. #include<cstdio> #include ...
- 【块状树】【LCA】bzoj1787 [Ahoi2008]Meet 紧急集合
分块LCA什么的,意外地快呢…… 就是对询问的3个点两两求LCA,若其中两组LCA相等,则答案为第三者. 然后用深度减一减什么的就求出距离了. #include<cstdio> #incl ...
- Exercise02_01
import java.util.Scanner; public class Out { public static void main(String[] args){ Scanner input = ...
- Matlab设置字体大小
1. 设置坐标轴上下限:axis([xmin,xmax,ymin,ymax]); 2. 设置图片大小:set(gcf,'Position',[x1,y1,dx,dy]); x1和y1是图的左下角坐 ...
- Linux内核regulator架构和编写
电源种类介绍 (百度百科)LDO是low dropout regulator,意为低压差线性稳压器,是相对于传统的线性稳压器来说的.传统的线性稳压器,如78xx系列的芯片都要求输入电压要比输出电压高出 ...
- PHP文件包含漏洞总结
0x00 前言 PHP文件包含漏洞的产生原因是在通过PHP的函数引入文件时,由于传入的文件名没有经过合理的校验,从而操作了预想之外的文件,就可能导致意外的文件泄露甚至恶意的代码注入. 最常见的就属于本 ...
- centos7.2 kvm虚拟化管理平台WebVirtMgr部署
在服务器上部署kvm虚拟化,虚出多台VM出来,以应对新的测试需求.当KVM宿主机越来越多,需要对宿主机的状态进行调控,决定采用WebVirtMgr作为kvm虚拟化的web管理工具,图形化的WEB,让人 ...