2473 - 概率论与数理逻辑第3章 第3题

通过次数

0

提交次数

0

时间限制 : 1 秒 内存限制 : 128 MB

设随机变量(X,Y)的概率密度为:


f(x,y)=    k(9-x-y),     0<x<3, 3<y<6.

                  0 ,            其他

请确定常数k

样例输入N=0,输出1

测试输入N=1,输出k值

<br />

题目输入

0

题目输出

1/8

输入/输出样例

输入格式

0

输出格式

1

C语言解答

#include <stdio.h>
 
int main()
{
    int a;
    while(scanf("%d",&a) != EOF)
 {
 if (a==1)
   {
    printf("1/27\n");
   }
 else if (a==0) 
     printf("1\n");	
 
  }
    return 0;
}

C++解答

#include <iostream>
#include <string>

using namespace std;

int main()
{
  int n ;
  string answer;
 
  while(scanf("%d",&n) != EOF)
  {
    if(n==1)
    {
	  answer = "1/27";
	  cout<<answer<<endl;
    }
    else if(n==0)
    {
      answer = "1";  
	  cout<<answer<<endl;
    }
	
  }
  return 0;
}

Java解答

import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner cin = new Scanner(System.in);
		int a;
		int b;
		while (cin.hasNext()) {
			a = cin.nextInt(); 
			if (a==1){
  int x=1;
  int y=27;
System.out.printf(x+"/"+y);
   
}
else if (a==0){
  b=1; 
System.out.printf("%d", b);}
}
		}
	}