poj-3440

0 篇文章 0 订阅
//148K	157MS	C++
#include <cstring>
#include <cstdio>

#define M_PI 3.14159265358979323846

using namespace std;

double Diameter;
double Radius;

double tileLength;
double width;
double height;
double totalSquare;

double OneTile(int height, int width, int tileLength, double Radius) {
	if (height * width == 1) {
		return 1.0;
	}

	if (height == 1) {
		int middleNum = width - 2;
		double square = 0;
		square += tileLength*(tileLength - Radius)*2;
		square += middleNum*(tileLength - 2*Radius)*tileLength;
		// printf("%lf\n", square);
		return square/totalSquare;
	} else if (width == 1) {
		int middleNum = height - 2;
		double square = 0;
		square += tileLength*(tileLength - Radius)*2;
		square += middleNum*(tileLength - 2*Radius)*tileLength;
		return square/totalSquare;
	}

	double square = 0;
	int middleNum = (height - 2) * (width - 2);
	if (middleNum < 0) {
		middleNum = 0;
	}
	int cornerNum = 4;
	int sideNotCornerNum = (height*width - cornerNum - middleNum);
	square += middleNum*(tileLength - Diameter)*(tileLength - Diameter);
	square += cornerNum*(tileLength - Radius)*(tileLength - Radius);
	square += sideNotCornerNum*(tileLength - Diameter)*(tileLength - Radius);
	return square/totalSquare;
}

double FourTile(int height, int width, int tileLength, double Radius) {
	if (height < 2 || width < 2) {
		return 0.0;
	}
	return ((height - 1)*(width - 1)*M_PI*(Radius)*Radius)/totalSquare;
}

double TwoTile(int height, int width, int tileLength, double Radius) {
	if (height * width == 1) {
		return 0.0;
	}

	int adjacent1 = 0; 
	int adjacent2 = 0;
	int adjacent3 = 0;
	int adjacent4 = 0;

	if (height == 1) {
		adjacent1 = 2;
		adjacent2 = width - 2;
		double square = 0;
		square += adjacent1 * Radius * (tileLength);
		//sepcial, left and after
		square += adjacent2 * Radius * (tileLength) * 2;
		return square/totalSquare;
	} else if (width == 1) {
		adjacent1 = 2;
		adjacent2 = height - 2;
		double square = 0;
		//special, left and after
		square += adjacent1 * Radius * (tileLength);
		square += adjacent2 * Radius * (tileLength) * 2;
		return square/totalSquare;
	} else {
		adjacent2 = 4;
		adjacent4 = (height-2)*(width-2);
		adjacent3 = height*width - adjacent2 - adjacent4;
	}

	double square = 0;
	square += adjacent1 * Radius * (tileLength); 
	square += adjacent2 * Radius * (tileLength - Radius) * 2;
	square += adjacent3 * ( Radius * (tileLength - Diameter) + Radius * (tileLength - Radius)*2);
	square += adjacent4 * Radius * (tileLength - Diameter) * 4;
	return square/totalSquare;
}

int caseNum;

int main() {
	scanf("%d", &caseNum);
	for (int i = 1; i <= caseNum; i++) {	
		scanf("%lf %lf %lf %lf", &height, &width, &tileLength, &Diameter);
		Radius = (double)Diameter/2;
		totalSquare = height * width * tileLength * tileLength;
		double P1Tile = OneTile(height, width, tileLength, Radius);
		double P2Tile = TwoTile(height, width, tileLength, Radius);
		double P4Tile = FourTile(height, width, tileLength, Radius);
		double P3Tile = 1 - P1Tile - P2Tile - P4Tile;
		if (P3Tile <0) {
			P3Tile = 0.0;
		}
		printf("Case %d:\n", i);
		printf("Probability of covering 1 tile  = %.4lf%%\n", P1Tile*100);
		printf("Probability of covering 2 tiles = %.4lf%%\n", P2Tile*100);
		printf("Probability of covering 3 tiles = %.4lf%%\n", P3Tile*100);
		printf("Probability of covering 4 tiles = %.4lf%%\n", P4Tile*100);
		if (i != caseNum) {
			printf("\n");
		}
	}
}
纯概率题,不过还是有些好的思路的.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值