首页 > ACM题库 > HDU-杭电 > hdu 2634 Doing Physics Experiment-[解题报告]C++
2014
02-12

hdu 2634 Doing Physics Experiment-[解题报告]C++

Doing Physics Experiment

问题描述 :

As far as Samuel is concerned,physics is very dull and doing the physics experiment is a waste of time. So Samuel only got a passing score in the experiment this semester. Dealing with the figures that get from the experiment requires a lot of energy and time,and it is not valuable to do it by press the calculator to get answer. So Samuel and his roommates often make up a program to work it out. Can you help Samuel make a program?
The problem is not hard. You only need to figure out the average M of n number(double type x1,x2,x3…xn) (the precision set as 10).

输入:

test cases t,each of a test case contains a number n(an integer) and n figures(double type).

输出:

test cases t,each of a test case contains a number n(an integer) and n figures(double type).

样例输入:

1
3 1.0 1.2 1.1

样例输出:

The average M = 1.1000000000.

 

#include <stdio.h>
int main()
{
double a,sum;
int n, i,ca;
scanf("%d", &ca);
while (ca--) {
scanf("%d", &n);
sum = 0;
for (i = 0; i < n; ++i) {
scanf("%lf", &a);
sum += a;
}
printf("The average M = %.10lf.\n", sum / n);
}
return 0;
}

 


  1. for(int i=1; i<=m; i++){
    for(int j=1; j<=n; j++){
    dp = dp [j-1] + 1;
    if(s1.charAt(i-1) == s3.charAt(i+j-1))
    dp = dp[i-1] + 1;
    if(s2.charAt(j-1) == s3.charAt(i+j-1))
    dp = Math.max(dp [j - 1] + 1, dp );
    }
    }
    这里的代码似乎有点问题? dp(i)(j) = dp(i)(j-1) + 1;这个例子System.out.println(ils.isInterleave("aa","dbbca", "aadbbcb"));返回的应该是false