Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

试了好几次,java的四舍五入怎么都不行呀,wa

Posted by sohu at 2008-01-19 21:19:01 on Problem 1857
import 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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator