百度2017暑期实习生编程钓鱼比赛

ss请cc来家里钓鱼,鱼塘可划分为n*m的格子,每个格子每分钟有不同的概率钓上鱼,cc一直在坐标(x,y)的格子钓鱼,而ss每分钟随机钓一个格子。问t分钟后他们谁至少钓到一条鱼的概率大?为多少?

输入描述:
第一行五个整数n,m,x,y,t(1≤n,m,t≤1000,1≤x≤n,1≤y≤m);
接下来为一个n*m的矩阵,每行m个一位小数,共n行,第i行第j个数代表坐标为(i,j)的格子钓到鱼的概率为p(0≤p≤1)


输出描述:
输出两行。第一行为概率大的人的名字(cc/ss/equal),第二行为这个概率(保留2位小数)

输入例子:
2 2 1 1 1
0.2 0.1
0.1 0.4

输出例子:
equal
0.20
 
 
 
import java.util.Scanner;
public class Main{
     public static void main(String[] args){
         Scanner in =  new Scanner(System.in);
         while (in.hasNext()) { //注意while处理多个case
             String[] s1 = in.nextLine().split( " " );
             int n = Integer.parseInt(s1[ 0 ]);
             int m = Integer.parseInt(s1[ 1 ]);
             int x = Integer.parseInt(s1[ 2 ]);
             int y = Integer.parseInt(s1[ 3 ]);
             int t = Integer.parseInt(s1[ 4 ]);
             //int n = in.nextInt();
             //int m = in.nextInt();
             //int x = in.nextInt();
             //int y = in.nextInt();
             //int t = in.nextInt();
             double ccp =  0.00 ;
             double ssp =  0.00 ;
             for ( int i =  1 ;i<=n;i++){
                 String[] s = in.nextLine().split( " " );
                 for ( int j =  1 ;j<=m;j++){
                     double p =  1 -Double.parseDouble(s[j- 1 ]);
                     //double p = 1-in.nextDouble();//钓不到鱼的概率
                     if (i==x&&j==y)
                         ccp = p;
                     ssp += p;
                 }
             }
             ssp /= (n*m); //期望
             if (ccp<ssp){
                 System.out.println( "cc" );
                 System.out.printf( "%.2f\n" 1 -Math.pow(ccp,t));
             } else if (ccp>ssp){
                 System.out.println( "ss" );
                 System.out.printf( "%.2f\n" 1 -Math.pow(ssp,t));
             } else {
                 System.out.println( "equal" );
                 System.out.printf( "%.2f\n" 1 -Math.pow(ccp,t));
             }
         }
     }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值