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 |
试了好几次,java的四舍五入怎么都不行呀,waimport java.util.*; import java.math.*; public class pku1857 { static int[] w; static int[] s; static double[] time; public static void main(String args[]) { Scanner sc=new Scanner(System.in); w=new int[1001]; s=new int[1001]; time=new double[1001]; int sum,i,j; int speed; while(sc.hasNextInt()) { int b=sc.nextInt(); int l=sc.nextInt(); int n=sc.nextInt(); if(b+l+n==0)break; for(i=1;i<=n;i++) { w[i]=sc.nextInt(); s[i]=sc.nextInt(); } for(i=1;i<=n;i++) time[i]=Double.MAX_VALUE; time[0]=0.0; for(i=1;i<=n;i++) { sum=0;speed=Integer.MAX_VALUE; for(j=1;j<=i;j++) { sum+=w[j]; if(sum>b)break; speed=Math.min(speed,s[j]); time[i]=Math.min(time[i],time[i-j]+l*1.0/speed); } } time[n]*=60; Double d=new Double(time[n]); String str=d.toString(); BigDecimal bd=new BigDecimal(str); BigDecimal bd1=bd.setScale(1,bd.ROUND_HALF_UP); System.out.println(bd1.doubleValue()); } } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator