首页 > 专题系列 > Java解POJ > POJ 2601 Simple calculations [解题报告] Java
2013
11-11

POJ 2601 Simple calculations [解题报告] Java

Simple calculations

问题描述 :

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 calculates a1.

输入:

The first line of an input contains an integer n. The next two lines consist of numbers a0 and an+1 each having two digits after decimal point, and the next n lines contain numbers ci (also with two digits after decimal point), one number per line.

输出:

The output file should contain a1 in the same format as a0 and an+1.

样例输入:

1
50.50
25.50
10.15

样例输出:

27.85

解题代码:

//* @author: [email protected]
import java.util.Scanner;
class Main
{
 public static void main(String[] args)
 {
   Scanner in=new Scanner(System.in);
   int n=in.nextInt();
   double a0=in.nextDouble();
   double an=in.nextDouble();
   double total=n*a0+an;
   double sum=0;
   int u=n;
   for(int i=0;i< n;i++,u--)
	sum+=in.nextDouble()*u;
   double ans=(total-sum*2)/(n+1);
   System.out.printf("%.2f",ans);
 }
}

  1. 我还有个问题想请教一下,就是感觉对于新手来说,递归理解起来有些困难,不知有没有什么好的方法或者什么好的建议?

  2. This write-up presents the gentle in which we can notice the fact. this is extremely wonderful one and gives in depth info.

  3. 你的理解应该是:即使主持人拿走一个箱子对结果没有影响。这样想,主持人拿走的箱子只是没有影响到你初始选择的那个箱子中有奖品的概率,但是改变了其余两个箱子的概率分布。由 1/3,1/3 变成了 0, 2/3