标签:
#include <stdio.h> double dp[50001]; int main(){ int n; dp[1]=1; dp[2]=3; for(int i=3;i<=50000;i++){ dp[ i ] = 2 * dp[ i - 1 ] - dp[ i - 2 ] + ( 2.0 / i ); } while(scanf("%d",&n)==1 && n){ printf("%.2lf\n",dp[n]); } }
import java.util.Scanner; public class Main { public static double[] dp = new double[ 50001 ]; public static void dp() { dp[ 1 ] = 1; dp[ 2 ] = 3; for( int i = 3; i <= 50000; i++ ) { dp[ i ] = 2 * dp[ i - 1 ] - dp[ i - 2 ] + ( 2.0 / i ); } } public static void main( String[] args ) { Scanner sc = new Scanner( System.in ); dp(); while( sc.hasNext() ) { int n = sc.nextInt(); if( n == 0 ) return; else { System.out.printf( "%.2f\n", dp[ n ] ); } } } }
求Java老司机讲解下为何卡浮点呀。。。。
标签:
原文地址:http://www.cnblogs.com/dick159/p/5578374.html