程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> UVA - 11346 Probability (概率)

UVA - 11346 Probability (概率)

編輯:C++入門知識

UVA - 11346 Probability (概率)


Description

Download as PDF

G - Probability

Time Limit: 1 sec
Memory Limit: 16MB

Consider rectangular coordinate system and point L(X,Y) which is randomly chosen among all points in the area A which is defined in the following manner: A = {(x,y) | x is from interval [-a;a]; y is from interval [-b;b]}. What is the probability P that the area of a rectangle that is defined by points (0,0) and (X,Y) will be greater than S?

INPUT:

The number of tests N <= 200 is given on the first line of input. Then N lines with one test case on each line follow. The test consists of 3 real numbers a > 0, b > 0 ir S => 0.

OUTPUT:

For each test case you should output one number P and percentage " %" symbol following that number on a single line. P must be rounded to 6 digits after decimal point.

SAMPLE INPUT:

3
10 5 20
1 1 1
2 2 0

SAMPLE OUTPUT:

 23.348371%
0.000000%
100.000000%
題意:給定a,b,s要求在[-a,a]選定x,在[-b,b]選定y,使得(0, 0)和(x, y)組成的矩形面積大於s的概率
思路:轉換成x*y > s的圖形面積,利用求導函數求面積的方式計算,y=s/x的導函數是y=s*lnx
#include 
#include 
#include 
#include 
#include 
using namespace std;

int main() {
	int t;
	double a, b, s;
	scanf("%d", &t);
	while (t--) {
		scanf("%lf%lf%lf", &a, &b, &s);
		if (a * b <= s) {
			puts("0.000000%");
			continue;
		}
		if (s == 0) {
			puts("100.000000%");
			continue;
		}
		printf("%lf%%\n", 100 - (s + s * (log(a) - log(s / b))) / a / b * 100);
	}
	return 0;
}


  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved