Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
利用穷举法import java.util.Scanner; public class Solve1 { /** * @param args */ public static void main(String[] args) { Scanner scan=null; double c; int i; scan=new Scanner(System.in); while(scan.hasNext()) { c=scan.nextDouble(); if(c==0.0) break; for( i=1;;i++) if(newSum(i)>=c) break; System.out.println(i+" card(s)"); } } public static double newSum(int n) { double sum=0.0; for(double i=1.0;i<=n;i++) sum=sum+1/(i+1); return sum; } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator