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 |
Re:大家可以用概率的阶乘公式来过,不过要用double,不然wa,符Ac java代码,注,double表示的数比long的大In Reply To:大家可以用概率的阶乘公式来过,不过要用double,不然wa Posted by:Jack_whj at 2013-12-03 17:26:27 import java.util.*; public class Main { public static void main(String[] args) { // TODO Auto-generated method stub Scanner sca=new Scanner(System.in); while(true){ double ai=sca.nextInt(); double bi=sca.nextInt(); if(ai==0&&bi==0){ break; }else{ double pd=ai/2; if(bi<=pd){ double sum=1; double start=ai-bi; for(double i=start+1;i<=ai;i++){ sum=sum*i; } long sum2=1; for(long i=2;i<=bi;i++){ sum2=sum2*i; }System.out.println(String.format("%.0f", sum/sum2)); }else{ double sum=1; double start=ai-bi; for(double i=bi+1;i<=ai;i++){ sum=sum*i; } double sum2=1; for(double i=1;i<=start;i++){ sum2=sum2*i; }System.out.println(String.format("%.0f", sum/sum2)); } } } } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator