ZOJ3411 Special Special Judge

问题描述:

The norm of a vector v = (v1, v2, ... , vn) is define as norm(v) = |v1| + |v2| + ... + |vn|. And in Problem 0000, there are n cases, the standard output is recorded as a vector x = (x1, x2, ... , xn). The output of a submitted solution is also records as a vector y = (y1, y2, ... , yn). The submitted solution will be accepted if and only if norm(x - y)m (a given tolerance).

    Knowing that all the output xi are in range [a, b], an incorrent solution that outputs integer yi in range [a, b] with equal probability may also get accepted. Given the standard output xi, you are supposed to calculate the possibility of getting accepted using such solution.

n, m, a, b (1 ≤ n, m ≤ 50, -50 ≤ a < b ≤ 50)

Accepted 3411Java380MS9938K
 
  
import java.util. * ;
import java.math. * ;

public class Main{
public static void main(String[] args){
int n,m,a,b,x[] = new int [ 51 ];
BigInteger d[][]
= new BigInteger[ 51 ][ 51 ],f1,f2,f3;
Scanner cin
= new Scanner(System.in);
while (cin.hasNext()) {
n
= cin.nextInt();
m
= cin.nextInt();
a
= cin.nextInt();
b
= cin.nextInt();
// System.out.println(n+" "+m+" "+a+" "+b);
int i,j,k,t;
for (i = 1 ;i <= n;i ++ )
x[i]
= cin.nextInt();
for (i = 0 ;i <= n;i ++ )
for (j = 0 ;j <= m;j ++ )
d[i][j]
= BigInteger.ZERO;
for (i = a;i <= b;i ++ ){
t
= Math.abs(i - x[ 1 ]);
// System.out.println(t);
if (t <= m) {
d[
1 ][t] = d[ 1 ][t].add(BigInteger.ONE);
// System.out.println("d[1]["+t+"]="+d[1][t]);
}
}

for (i = 2 ;i <= n;i ++ ){
for (j = a;j <= b;j ++ ){
t
= Math.abs(j - x[i]);
if (t <= m){
for (k = t;k <= m;k ++ ){
d[i][k]
= d[i][k].add(d[i - 1 ][k - t]);
// System.out.println("d["+i+"]["+k+"]="+d[i][k]);
}
}
}
}
f1
= BigInteger.ZERO;
for (i = 0 ;i <= m;i ++ )
f1
= f1.add(d[n][i]);
f2
= BigInteger.ONE;
for (i = 1 ;i <= n;i ++ )
f2
= f2.multiply(BigInteger.valueOf(b - a + 1 ));
// System.out.println(f1+" "+f2);
f3 = f1.gcd(f2);
f1
= f1.divide(f3);
f2
= f2.divide(f3);
System.out.println(f1
+ " / " + f2);
}
}
}
/*
1 1 0 2
1
4 2 2 5
2 3 2 4
4 3 2 5
2 3 2 4

1/1
3/32
7/32
*/

代码的核心部分是Lines 30-40。简单吧,嘻嘻…

转载于:https://www.cnblogs.com/DreamUp/archive/2010/10/09/1846717.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值