首页 > 试题广场 >

钓鱼比赛

[编程题]钓鱼比赛
  • 热度指数:25882 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32M,其他语言64M
  • 算法知识视频讲解
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位小数)
示例1

输入

2 2 1 1 1
0.2 0.1
0.1 0.4

输出

equal
0.20
#include<iostream>
#include<iomanip>
#include<vector>
#include<cmath>
using namespace std;
int main(){
	int n,m,x,y,t;
	while(cin>>n>>m>>x>>y>>t){
		vector< vector<float> > p(n,vector<float>(m));//动态申请二维数组空间 
		float sum=0;
		for(int i=0;i<n;i++){
			for(int j=0;j<m;j++){
				cin>>p[i][j];
				sum+=p[i][j];
			}
		}
		float cc=1-pow(1-p[x-1][y-1],t);
		float ss=1-pow(1-sum/n/m,t);
		if(cc>ss){
			cout<<"cc"<<endl;
			cout<<setprecision(2)<<cc<<endl;
		}else if(cc<ss){
			cout<<"ss"<<endl;
			cout<<setprecision(2)<<ss<<endl;	
		}else{
			cout<<"equal"<<endl;
			cout<<setprecision(2)<<ss<<endl;
		}
	}
	return 0;
} 
不知哪里错了。。。。求指教
编辑于 2017-04-25 22:00:19 回复(1)
更多回答
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));
            }
        }
    }
}

java的数据按照行读取,时间不会超时
发表于 2016-04-11 09:46:56 回复(7)
一看题目挺简单,做了才发现坑还挺多的
至少钓一条的概率,还有两位小数
//c++ 可以用这个控制输出
#include<iomanip>
if(cc>ss) cout<<"cc"<<setprecision(2)<<setiosflags(ios::fixed)<<endl<<cc<<endl;

编辑于 2017-07-18 15:03:52 回复(0)
//运行通过
#include<iostream>
#include<iomanip>
#include<math.h>
using namespace std;

int main()
{
	int row,column,x,y,minute;
	while (cin >> row >> column >> x >> y >> minute)
	{
		double ** pArray = new double* [row];
		for (int i = 0; i < row; ++i)
			pArray[i] = new double[column];

		for (int i = 0; i < row;++i)
		for (int j = 0; j < column; ++j)
			cin >> pArray[i][j];

		double pCC = pArray[x-1][y-1];
		double pSS = 0.0;
		for (int i = 0; i < row;++i)
		for (int j = 0; j < column; ++j)
			pSS += pArray[i][j];
		pSS = pSS / row / column;

		cout << setiosflags(ios::fixed) << setprecision(2);
		if (pSS < pCC)
			cout << "cc" << endl << 1 - pow(1 - pCC, minute) << endl;
		else {
			if (pCC < pSS)
				cout << "ss" << endl << 1 - pow(1 - pSS, minute) << endl;
			else
				cout << "equal" << endl << 1 - pow(1 - pSS, minute) << endl;
		}

		for (int i = 0; i < row; ++i)
			delete[]pArray[i];
		delete[]pArray;
	}
	return 0;
}

发表于 2015-10-05 14:28:13 回复(0)
while 1:
    try:
        s = raw_input()
    except:
        break
    n, m, x, y, t = map(float, s.split())
    s = 0.0
    for i in range(int(n)):
        d = map(float, raw_input().split())
        s += sum(d)
        if x - 1 == i:
            p1 = d[int(y) - 1]
    p2 = s / (n * m)
    t = [('cc', 1 - (1 - p1) ** t), ('ss', 1 - (1 - p2) ** t)]
    t.sort(key=lambda d: d[1])
    print 'equal' if t[0][1] == t[1][1] else t[-1][0]
    print '%.2f' % t[-1][1]

发表于 2017-04-30 15:39:23 回复(0)
#include<iostream>
#include<vector>
#include<cmath>
#include <iomanip>
using namespace std;
int main(){
    int n,m,x,y,t;
    while(cin>>n>>m>>x>>y>>t){
        double sum=0;
        vector<vector<double>> p(n,vector<double>(m,0.0));
        for(int i=0;i<n;++i){
           for(int j=0;j<m;++j){
                cin>>p[i][j];
                sum+=p[i][j];
            }
        }
        double pcc,pss;
        pcc=1-pow(1-p[x-1][y-1],t);
        pss=1-pow(1-sum/(n*m),t);
        if(pcc>pss){
            cout<<"cc"<<endl<<setiosflags(ios::fixed)<< setprecision(2)<<pcc<<endl;
        }
        else if(pcc<pss){
            cout<<"ss"<<endl<<setiosflags(ios::fixed)<< setprecision(2)<<pss<<endl;
        }
        else
            cout<<"equal"<<endl<<setiosflags(ios::fixed)<< setprecision(2)<<pss<<endl;
    }
    return 0;
}

发表于 2017-02-21 18:22:33 回复(0)
萌头像
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <iomanip>
using namespace std;
int main()
{
	int n, m, x, y, t;
	
	while (cin >> n>>m>>x>>y>>t)
	{
		vector<vector<double>> f(n + 1, vector<double>(m + 1, 0.0));
		double sum = 0.0;
		for (size_t i = 1; i < n+1; i++)
		{
			for (int j = 1; j < m+1; j++)
			{
				cin >> f[i][j];
				sum += f[i][j];
			}
		}
		double cc = 1 - pow(1.0-f[x][y], t);
		double ss = sum /(m*n);
		ss = 1 - pow(1.0 - ss, t);
		if (cc==ss)
		{
			cout << "equal" << endl<<setiosflags(ios::fixed)<< setprecision(2) << ss << endl;
		}
		else if(cc>ss)
		{
			cout << "cc" <<endl <<setiosflags(ios::fixed)<< setprecision(2) << cc << endl;
		}
		else
		{
			cout << "ss" << endl <<setiosflags(ios::fixed)<< setprecision(2) << ss << endl;
		}

	}
	return 0;
}

发表于 2016-09-06 17:22:46 回复(0)
// 求纠错,牛客的OJ系统,还需要学习啊
import java.text.DecimalFormat;
import java.io.*;
import java.util.*;

public class Main {
    public static Double[] solution3(double[][] a, int n, int m, int x, int y, int t){
        double res = 0;
        double cc = 1-Math.pow(1-a[x][y], t); // 1-(1-P)^t
        double ss_r = 1;
        for(int i=0;i<t;i++){
            int x0 = (int)Math.random()*n;
            int y0 = (int)Math.random()*m;
            ss_r *= 1-a[x0][y0]; // (1-P)^t

        }
        double ss = 1 - ss_r; // 1-(1-P)^t

        return new Double[]{cc, ss};
    }
     
    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        int n = cin.nextInt();
        int m = cin.nextInt();
        int x = cin.nextInt()-1;
        int y = cin.nextInt()-1;
        int t = cin.nextInt();
        double[][] a = new double[n][m];
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                a[i][j] = cin.nextDouble();
            }
        }
        Double[] res = solution3(a, n, m, x, y, t);
        if(res[0]-res[1]>=0.01){
            System.out.println("cc");
            System.out.println(new DecimalFormat("0.00").format(res[0]));
        }
        else if(res[0]-res[1]<=-0.01){
            System.out.println("ss");
            System.out.println(new DecimalFormat("0.00").format(res[1]));
        }
        else{
            System.out.println("equal");
            System.out.println(new DecimalFormat("0.00").format(res[0]));
        }
    }
}

发表于 2015-09-27 07:14:44 回复(7)
        这是个纯数学问题,设计概率学知识,应该是古典概型吧!掌握了算法编程时没有什么问题的。下面我来说一下解题思路供大家参考。
        我们将示例改一下,变为如下输入更能说明一般性:
                                        2       2       1       1       2
                                        0.2       0.1
                                        0.1       0.4
        我们来算两次钓鱼概率。
        首先,我们来算cc的。第一次钓鱼,概率没的说,0.2。注意!第二次时,也就是说他第一次没有钓上来才会出现第二次钓,如果第一次钓上来他就赢了。所以概率为 (1 - 0.2) * 0.2 = 0.16。这个公式应该懂,如果遗忘回去翻看下高中排列组合部分计算古典概型的知识。所以,cc钓上来的概率是第一次钓上来或者第二次钓上来,因此这里使用组合,0.2 + 0.16 = 0.36。即两次钓上鱼来的概率为0.36。
        我们再来看ss的。由于题目没有强调ss的喜好,所以我们视ss为无差别选择垂钓地点,每次选择相互独立。什么意思呢,就是个垂钓地点等概论且两次可以选择同一个地方。所以说ss每次垂钓的钓上来的概率是 1/mn(sum(pob[i])),i=1,2,3,...,mn。牛客的公式编辑器有点问题,只能这么打……我说一下,以我上面提到的实例为例,怎么算的呢?由于ss选择(1,1)的概率跟选择其他的地方是一样的,即1/(2*2),也就是0.25,那么在该区域钓到鱼的概率就是0.25*0.2=0.05。同理,可以推得其他地方。由于只需要在一个地方掉,这里使用组合,那么这个推导公式就是0.25*0.2+0.25*0.1+0.25*0.1+0.25*0.4。进行提取公因式处理,我们会发现其实这个递推关系式就是(1/(m*n))*(所有区域概率和)。因此此例ss概率为0.2。然后第二次垂钓的概率就与cc算法一样了,同样是0.36。
        因此,在编程时,可以选择在数据输入时直接记录概率和和对应cc的概率位置,然后只需要进行一次遍历填完各地区概率大小然后相加即可。时间复杂度是O(t)。感觉已经很快了,但是使用C++实现实际运行时间居然要 400 ms!!如果有小伙伴的运行时间能跑如个位数务必留下思路,实在是没有发现能将时间复杂度将至O(logn)的方法。参考代码如下:
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main(void)
{
    int n, m, x, y, t;
    while (cin >> n >> m >> x >> y >> t){
        double nub, pobsum = 0, pobc = 0, pobs = 0;
        double *pobcc = new double[t], *pobss = new double[t];
        for (int i = 1; i <= n; i++)
        {
            for (int j = 1; j <= m; j++)
            {
                cin >> nub;
                pobsum += nub;      //求各点概率和,以求ss概率
                if (i == x && j == y) pobc = nub; //记录cc概率
            }
        }
        pobs = pobsum / (n * m);
        pobcc[0] = pobc, pobss[0] = pobs;
        for (int i = 1; i < t; i++)
        {
            pobcc[i] = pow(1 - pobc, i)*pobc; //计算各次概率
            pobss[i] = pow(1 - pobs, i)*pobs;
        }
        pobc = 0, pobs = 0;
        for (int i = 0; i < t; i++)
        {
            pobc += pobcc[i];     //各次概率相加
            pobs += pobss[i];
        }
        cout.setf(ios::fixed);
        if (pobc > pobs) cout << "cc\n" << setprecision(2) << pobc << endl;
        else if (pobc < pobs) cout << "ss\n" << setprecision(2) << pobs << endl;
        else cout << "equal\n" << setprecision(2) << pobc << endl;
        delete []pobss, delete []pobcc;  
    }
    return 0;
}

发表于 2018-03-30 09:57:35 回复(0)
#include <bits/stdc++.h>

using namespace std;

int main()
{     int n,m,x,y,t;     while(cin>>n>>m>>x>>y>>t)     {         double p1=0,p2=0;         for(int i=1;i<=n;i++)             for(int j=1;j<=m;j++)             {                 double p;                 cin>>p;                 p = 1-p;                 if(i==x && j==y)                     p1 = p;                 p2 += p;             }         p2 /= n*m;         if(p1 < p2)             printf("cc\n%.2f\n", 1-pow(p1,t));         else if(p1 > p2)             printf("ss\n%.2f\n", 1-pow(p2,t));         else             printf("equal\n%.2f\n", 1-pow(p1,t));     }     return 0;
}

发表于 2017-12-05 02:15:26 回复(0)
// 一个概率计算问题,但是里面有很多细节问题需要注意
import java.util.Scanner; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int n = 0; int m = 0; int x = 0; int y = 0; int t = 0; double temp = 0.0; double p_cc = 0.0; double p_ss = 0.0; while(sc.hasNext()){ n = sc.nextInt(); m = sc.nextInt(); x = sc.nextInt(); y = sc.nextInt(); t = sc.nextInt(); sc.nextLine(); temp = 0.0; p_cc = 0.0; p_ss = 0.0; for(int i=1;i<=n;i++){ String[] conten = sc.nextLine().split(" "); for(int j=1;j<=m;j++){ temp = Double.parseDouble(conten[j-1]); p_ss += temp; if(i==x && j==y)p_cc = temp; } } p_ss = p_ss/(m*n); if(p_ss>p_cc){ System.out.println("ss"); System.out.println(String.format("%.2f", 1.0-Math.pow(1.0-p_ss,t))); }else if(p_ss<p_cc){ System.out.println("cc"); System.out.println(String.format("%.2f", 1.0-Math.pow(1.0-p_cc,t))); }else{ System.out.println("equal"); System.out.println(String.format("%.2f", 1.0-Math.pow(1.0-p_cc,t))); } } } }
编辑于 2017-09-01 10:15:07 回复(0)
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<vector>
using namespace std;

int main()
{
    int n,m,x,y,t;
    while(cin>>n>>m>>x>>y>>t)
      {
         vector<vector<double> > a(n,vector<double>(m,0.0));
         double sumProb=0;
         for(int i=0;i<n;++i)
           {
              for(int j=0;j<m;++j)
               {
                   cin>>a[i][j];
                   sumProb+=a[i][j];  
               } 
           }
         double pcc=1-pow(1-a[x-1][y-1],t);
         double pss=1-pow(1-sumProb/n/m,t);    //sumProb/n/m为平均概率,其实就是随机概率
         if(pcc>pss)
            {                        //首先,需要包含头文件#include<iomanip>,该头文件控制输入输出流的格式,
               cout<<"cc"<<endl;     //其次:setiosflags(iOS::fixed)与后面的setprecision(1)连用可以控制输出小数小数点后面的位数。
               cout<<setiosflags(ios::fixed)<<setprecision(2)<<pcc<<endl;  
            }
         else if(pcc<pss)
            {
               cout<<"ss"<<endl;
               cout<<setiosflags(ios::fixed)<<setprecision(2)<<pss<<endl;
            }
         else
           {
               cout<<"equal"<<endl;
               cout<<setiosflags(ios::fixed)<<setprecision(2)<<pss<<endl;
           }
      } 
    return 0;
}

发表于 2017-07-31 19:42:21 回复(0)
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <cstdio>
 
using namespace std;
 
intmain() {
    intn, m, x, y, t;
    while(cin >> n >> m >> x >> y >> t) {
        vector<vector<double>> matrix(n, vector<double>(m));
        doublesum = 0;
        for(inti = 0; i != m * n; ++i) {
            cin >> matrix[i / m][i % m];
            sum += matrix[i / m][i % m];
        }
         
        doublep_cc = 1- pow(1- matrix[x-1][y-1], t);
        doublep_ss = 1- pow(1- sum / (m*n), t);
        if(abs(p_cc - p_ss) < 1e-5) {
            printf("equal\n%.2f\n", p_cc);
        } elseif(p_cc > p_ss) {
            printf("cc\n%.2f\n", p_cc);
        } else{
            printf("ss\n%.2f\n", p_ss);
        }
         
    }
     
    return0;
}

发表于 2017-03-14 22:00:46 回复(0)
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		while(in.hasNext()){
			int n=in.nextInt();
			int m=in.nextInt();
			int x=in.nextInt();
			int y=in.nextInt();
			int t=in.nextInt();
			in.nextLine();//吸取换行符
			int len=n*m;
			double ss=0,cc=0;
			double arr[][]=new double[n][m];
			
//			for (int i = 0; i < n; i++) {
//				for (int j = 0; j < m; j++) {
//					double d=in.nextDouble();
//					arr[i][j]=d;
//					ss+=d;
//				}
//			}
            
			for (int i = 0; i < n; i++) {
                //将第一行读到的数字按照空格分开存放在字符串数组中,这个数组的大小就是m
                String[] content = in.nextLine().split(" ");
                for (int j = 0; j < m; j++) {
                    //然后再把没一个字符串强转放到二维数组里面就好了
                	double d=Double.parseDouble(content[j]);
                    arr[i][j] = d;
                    ss+=d;
                }
            }
			
			cc=arr[x-1][y-1];
			ss/=len;
			
			double rss=1-Math.pow(1-ss, t);
			double rcc=1-Math.pow(1-cc, t);
			
			if(rss>rcc){
				System.out.println("ss");
				System.out.format("%.2f\n",rss);
			}
			else if(rss==rcc){
				System.out.println("equal");
				System.out.format("%.2f\n",rss);
			}
			else{
				System.out.println("cc");
				System.out.format("%.2f\n",rcc);
			}
		}
	}
}
注释掉的代码,不知道为何通过30%就报超时,我很郁闷跟注释这部分下面这种接受输入数据的算法区别有什么不一样吗?O(n^2)
发表于 2016-11-08 05:56:55 回复(0)
这样写为啥不对,求解答
#include<cstdio>
#include<cmath>
 
float arr[1000+1][1000+1]={0};
 
int main(){
    int rows,cols;
    int x,y;
    int t;
    scanf("%d %d %d %d %d",&rows,&cols,&x,&y,&t);
    double statc_b=0;
    for(int i=1;i<=rows;i++){
        for(int j=1;j<=cols;j++){
            scanf("%f",&arr[i][j]);
            statc_b+=arr[i][j];
        }
    }
    double stac_a=arr[x][y];
    double all_stac_a=pow(1-stac_a,t);
     
    double statc_b_2=statc_b/(rows*cols);
    double all_stac_b=pow(1-statc_b_2,t);
     
    if(fabs(all_stac_a-all_stac_b)<0.0001){
        printf("equal\n");
        printf("%.2f\n",1-all_stac_a);
    }else if(all_stac_a<all_stac_b){
        printf("cc\n");
        printf("%.2f\n",1-all_stac_a);
    }else{
        printf("ss\n");
        printf("%.2f",1-all_stac_a);
    }    
}

发表于 2016-09-07 08:57:14 回复(0)
//每次钓到鱼的概率为p,t分钟后钓到一条鱼概率为1-(1-p)^t
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>

using namespace std;

int main(){
    int n,m,x,y,t;
    while(cin>>n>>m>>x>>y>>t){
        vector<vector<float>> matrix(n,vector<float>(m,0));
        float CCpro = 0;
        float SSpro = 0;
        for(int i=0; i<n; ++i){
            for(int j=0; j<m; ++j){
                cin >> matrix[i][j];
                if(i==x-1&&j==y-1)
                    CCpro = matrix[i][j];
                SSpro += matrix[i][j];
            }
        }
        SSpro = SSpro/(m*n);
        double ret = 0;
        if(SSpro == CCpro){
            cout<<"equal"<<endl;
            ret = 1- pow(1-SSpro,t);
            printf("%.2f\n",ret);
        }
        if(SSpro > CCpro){
            cout<<"ss"<<endl;
            ret = 1- pow(1-SSpro,t);
            printf("%.2f\n",ret);
        }
        if(SSpro < CCpro){
            cout<<"cc"<<endl;
            ret = 1- pow(1-CCpro,t);
            printf("%.2f\n",ret);
        }
        
    }
    return 0;
}

发表于 2016-09-03 20:11:43 回复(0)
//以示例为例,对于cc而言,每次钓到鱼的概率p=0.2,t分钟后至少钓到一条鱼的概率pcc=1-(1-0.2)^t,
//对于ss,有n*m=4个位置供选择,故选择每个位置的概率为1/4,故每次钓到鱼的概率为p=1/4*0.2+1/4*0.1+1/4*0.1+1/4*0.4,
//故t分钟后至少钓到一条鱼的概率为pss=1-(1-p)^t。最后比较pcc和pss并输出。
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
double prob[1005][1005];
 
int main(){
    int n, m, x, y, t;
    while(cin >> n >> m >> x >> y >> t){
        int i, j;
        double sum = 0.0;
        for(i = 1; i <= n; ++i)
            for(j = 1; j <= m; ++j){
                cin >> prob[i][j];
                sum += prob[i][j];
            }
        double pcc = 1.0 - pow((1 - prob[x][y]), t);
        double pss = sum / (n*m);//钓到鱼的随机概率
        pss = 1.0 - pow((1 - pss), t);
        if(pss == pcc)
            cout << "euqal\n" << fixed << setprecision(2) << pcc << endl;
        else if(pss > pcc)
            cout << "ss\n" << fixed << setprecision(2) << pss << endl;
        else
            cout << "cc\n" << fixed << setprecision(2) << pcc << endl;
    }
    return 0;
}

发表于 2016-08-23 12:47:14 回复(0)
import java.util.Scanner;

public class Main {
/**
 * 非要逐行读取才不超时!
 */
	//思路:cc:固定某点概率;ss:所有点求平均概率,再由独立事件公式求t分钟后
	public static void main(String[] args) {
	
		Scanner reader = new  Scanner(System.in);
		while(reader.hasNext()){
			String[] s1 = reader.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]);
			double proCC = 0;
			double sumPro = 0;
			for(int i=1; i<=n; i++){	
				String[] s = reader.nextLine().split(" ");
				for(int j=1; j<=m; j++){
					double p = Double.parseDouble(s[j-1]);
					sumPro += p;
					if((i == x) && (j == y)){
						proCC = p;		
					}
				}
			}
			sumPro /= (n*m);
			//!注意这里:t个独立事件:P(t1Ut2Ut3..Utn) = 1-P(非t1)P(非t2)...P(非t3)
			if(proCC == sumPro){
				System.out.println("equal");
				System.out.println(String.format("%.2f", 1 - Math.pow(1-proCC, t)));		//保留小数点后两位
			}else if(proCC > sumPro){
				System.out.println("cc");
				System.out.println(String.format("%.2f", 1 - Math.pow(1-proCC, t)));
			}else if(proCC < sumPro){
				System.out.println("ss");
				System.out.println(String.format("%.2f", 1 - Math.pow(1-sumPro, t)));
			}
		}
	}

}


发表于 2016-04-21 18:50:36 回复(1)
 这题也要考虑多次输入,还有就是数组的下标。


发表于 2015-09-28 00:01:43 回复(0)
import java.util.Scanner;
//题目并不难,已通过,
//简单的说一下吧,首先我也不知道他这个输入时按照行来输入的,
//所以看了牛友的讨论才知道,输入是按照行扫描的,表示又涨姿势了
//另外就是注意题目描述,之少钓到一条鱼的概率,不要忽略了之少这个关键字。
//所以就可以考虑对立事件了。一条鱼也钓不到的概率。然后用1减去对立事件概率就解决了
public class Main{
    public static void fish(double[][] rectangle, double cc, int t) {
        //count记录所有格子的累加概率之和。因为随机钓一个格子,所以钓每个格子的概率
        //都是一样的,都是等概率。
        double ss = 0;
        for (int i = 0; i < rectangle.length; i++) {
            for (int j = 0; j < rectangle[0].length; j++) {
                ss += rectangle[i][j];
            }
        }
        //用累加的概率之和除以格子的总数,就是ss在每个格子钓到鱼的平均概率。
        //也就相当于他固定在一个格子上进行钓鱼。这个格子的概率也是固定的。
        ss = ss / (rectangle.length * rectangle[0].length);
        if (ss > cc) {
            System.out.println("ss");
            //因为至少调到一条鱼的情况比较多,所以考虑对立事件,一个鱼也钓不到的情况
            //又因为每分钟钓到鱼和钓不到鱼都是独立事件,互不影响,(感觉又回到高中了 = =)
            //把每分钟钓不到鱼的概率相乘,也就是求它的t次方,就是t分钟钓不到鱼的概率了。
            //最后用1减去这个概率就是能钓到鱼的概率了。
            //下面的分析同理。
            System.out.println(String.format("%.2f", 1 - Math.pow(1 - ss, t)));
        } else if (cc > ss) {
            System.out.println("cc");
            System.out.println(String.format("%.2f", 1 - Math.pow(1 - cc, t)));
        } else {
            System.out.println("equal");
            System.out.println(String.format("%.2f", 1 - Math.pow(1 - cc, t)));
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        do {
            int n = sc.nextInt();
            int m = sc.nextInt();
            int x = sc.nextInt() - 1;
            int y = sc.nextInt() - 1;
            int t = sc.nextInt();
            //注意一定要换行
            sc.nextLine();
            double[][] rectangle = new double[n][m];
            for (int i = 0; i < n; i++) {
                //将第一行读到的数字按照空格分开存放在字符串数组中,这个数组的大小就是m
                String[] conten = sc.nextLine().split(" ");
                for (int j = 0; j < m; j++) {
                    //然后再把没一个字符串强转放到二维数组里面就好了
                    rectangle[i][j] = Double.parseDouble(conten[j]);
                }
            }
            fish(rectangle, rectangle[x][y], t);
        } while (sc.hasNext());
    }
}

编辑于 2016-08-25 20:03:40 回复(5)
#include<iostream>
#include<iomanip>
#include<math.h>

using namespace std;

int main()
{
	int n,m,x,y,t;
	float cc,ss,equal;
	while(cin>>n>>m>>x>>y>>t)
 {
	float **p;
	p=new float *[n];
	for(int i=0;i<n;i++)
	p[i]=new float[m];
	for(int i=0;i<n;i++)
	for(int j=0;j<m;j++)
	{
		cin>>p[i][j];
	}
	
	cc=1-pow((1-p[x-1][y-1]),t);
	ss=0;
	for(int i=0;i<n;i++)
	for(int j=0;j<m;j++)
	ss+=p[i][j];

    ss=ss/m/n;
    
    ss=1-pow(1-ss,t);
    cout.setf(ios::fixed);
    if(ss==cc)
    {  
       equal=ss;
       cout<<"equal"<<endl;
	cout<<setprecision(2)<<equal<<endl;
    }
     if(ss<cc)
    {  
       cout<<"cc"<<endl;
	cout<<setprecision(2)<<cc<<endl;
    }
     if(ss>cc)
    {  
       cout<<"ss"<<endl;
	cout<<setprecision(2)<<ss<<endl;
    }
  }
	return 0;
}

发表于 2015-10-12 20:47:46 回复(4)

问题信息

难度:
104条回答 20340浏览

热门推荐

通过挑战的用户

查看代码