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 ...
随机推荐
- HDU 1180 诡异的楼梯【BFS/楼梯随时间变化】
诡异的楼梯 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) Total Submis ...
- Jekins持续集成,gitlab代码仓库
http://blog.csdn.net/john_cdy/article/details/7738393
- mysql 获取当前日期及格式化(转)
MySQL 获取当前日期及日期格式 获取系统日期: NOW() 格式化日期: DATE_FORMAT(date, format) 注: date:时间字段,format:日期格式 select now ...
- python sql语句封装连接mysql
进行了代码优化,欢迎评审 #!/usr/bin/python # -*- coding:utf-8 -*- import logging logging.basicConfig(level=loggi ...
- luogu P1064 金明的预算方案
题目描述 金明今天很开心,家里购置的新房就要领钥匙了,新房里有一间金明自己专用的很宽敞的房间.更让他高兴的是,妈妈昨天对他说:“你的房间需要购买哪些物品,怎么布置,你说了算,只要不超过N元钱就行”.今 ...
- Ubuntu 16.04通过源码安装QUEM虚拟机
下载编译安装: wget http://download.qemu-project.org/qemu-2.9.0.tar.xz tar xvJf qemu-2.9.0.tar.xz cd qemu-2 ...
- Ubuntu 14 中 VirtualBox发生错误Kernel driver not installed (rc=-1908)
宿主系统是Ubuntu 14,在VirtualBox中安装 CentOS 6.5 时,提示如下错误: Kernel driver not installed (rc=-1908) 网友提供的解决方案: ...
- JS面向对象之作用域
作用域 词法作用域 作用域 域表示的就是范围,即作用范围 就是一个名字在什么地方能使用,在什么地方不能使用 块级作用域 块级别的作用范围 // 在 c , java 等编程语言中,下面的语法报错 { ...
- sting , CSting的区别
1.string 是C++中的字符串. 字符串对象是一种特殊类型的容器,专门设计来操作的字符序列. 不像传统的c-strings,只是在数组中的一个字符序列,我们称之为字符数组,而C + +字符串对象 ...
- spring融合activitymq-all启动报错的解决办法
报错信息: nested exception is java.lang.NoSuchMethodError: org.springframework.core.annotation.Annotated ...