uva 10014 Simple calculations

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

根据递推公式推倒出a1的公式。

a1=(n*a0+an+1-2*(n*c1+(n-1)*c2+...+cn))/(n+1);

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <algorithm>
 4 #define maxn 50000
 5 using namespace std;
 6
 7 double a1,a2;
 8 double c[maxn];
 9 int t;
10 int n;
11
12 int main()
13 {
14     scanf("%d",&t);
15     while(t--)
16     {
17         scanf("%d",&n);
18         scanf("%lf%lf",&a1,&a2);
19         double sum=n*a1+a2;
20         for(int i=1; i<=n; i++)
21         {
22             scanf("%lf",&c[i]);
23             sum-=2.0*(n+1-i)*c[i];
24         }
25         printf("%.2lf\n",sum/(n+1));
26         if(t!=0) printf("\n");
27     }
28     return 0;
29 }

时间: 2024-10-26 11:49:19

uva 10014 Simple calculations的相关文章

UVA Simple calculations (数学推导)

 Simple calculations  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 ca

【POJ】【2601】Simple calculations

推公式/二分法 好题! 题解:http://blog.csdn.net/zck921031/article/details/7690288 这题明显是一个方程组……可以推公式推出来…… 然而这太繁琐了!发现a[i]是满足单调性的话,我们就可以二分a[1],递推出a[n+1],进行验证…… 思维复杂度比推公式低到不知哪里去了,真是一种优秀的算法(然而我想不到,并没有什么*用……) 1 Source Code 2 Problem: 2601 User: sdfzyhy 3 Memory: 736K

poj 2601 Simple calculations

Simple calculations Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6559   Accepted: 3291 Description 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 f

UVA 10014(推公式)

题目链接:UVA 10014 解题思路: 第一个想法是高斯消元,但貌似复杂度有点高,于是开始推公式,想了好久. 推导过程: a[i-1] + a[i+1] = 2 * ( a[i] + c[i] ) a[1] + a[n] = a[0] + a[n+1] - c[1:n] n = 1, 2, 3, - n (n+1) * a[1] = n*a[0] +a[n+1] - ( n*c[1] + (n-1)*c[2] + - + c[n] ) 代码: #include <cstdio> #inclu

uva 12253 - Simple Encryption(dfs)

题目链接:uva 12253 - Simple Encryption 题目大意:给定K1,求一个12位的K2,使得KK21=K2%1012 解题思路:按位枚举,不且借用用快速幂取模判断结果. #include <cstdio> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; const ll ite=(1<<20)-1; ll N; /* l

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(精确到小数点后两位),每个数字占一行. Out

Uva 10912 Simple Minded Hashing (计数DP)

4th IIUC Inter-University Programming Contest, 2005 H Simple Minded Hashing Input: standard input Output: standard output Problemsetter: Sohel Hafiz All of you know a bit or two about hashing. It involves mapping an element into a numerical value usi

UVA 10994 Simple Addition

感觉这个一定要记下来涨教训啊.一开始找规律找错了.判断超麻烦还各种WA.浪费N个小时啊..人家几行就A了.太弱, #include <map> #include <set> #include <list> #include <cmath> #include <ctime> #include <deque> #include <stack> #include <queue> #include <cctype

UVA 10912 Simple Minded Hashing

题意就略了.刚一看被数据吓住了.看到字符要求严格递增.那么如果字串长大于26那必然方案数目为0:同时1+2+3....+24+25+26=351如果大于这个数也是不可能的 令dp[i][j][k]表示第i位为第j个字符和为K时的方案数目 那么 dp[i][j][k]=sum(dp[i-1][m][k-t])  {m<j;k-t尝试将第j位置为t} #include <map> #include <set> #include <list> #include <