import java.math.BigDecimal; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner cin = new Scanner(System.in); BigDecimal fac[] = new BigDecimal[10001]; fac[0] = BigDecimal.valueOf(1); for (int i = 1; i <= 10000; i++) fac[i] = fac[i - 1].multiply(BigDecimal.valueOf(i)); while (cin.hasNext()) { int p = cin.nextInt(), q = cin.nextInt(), r = cin.nextInt(), s = cin.nextInt(); BigDecimal ans = BigDecimal.ONE; ans = ans.multiply(fac[p]); ans = ans.divide(fac[q], 1000, BigDecimal.ROUND_HALF_UP); ans = ans.multiply(fac[s]); ans = ans.divide(fac[p - q], 1000, BigDecimal.ROUND_HALF_UP); ans = ans.multiply(fac[r - s]); ans = ans.divide(fac[r], 1000, BigDecimal.ROUND_HALF_UP); System.out.println(ans.setScale(5, BigDecimal.ROUND_HALF_UP)); } } }
Hello, I am a CS student from Taiwan.
I am learing English and Programming.
I'll save source code of some problems or small programs without comments in this blog.
I would recommend you not to read solution from others before you solved the problem.
(這邊專門存放沒有任何註解的小程式/OJ題目程式碼)
2013年1月1日
UVa 10375 - Choose and divide
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言