【NOIP2022 模拟赛 B 组 Day5】多边形【计算几何】

119 篇文章 0 订阅

在这里插入图片描述

思路:

直接计算线段右侧的点不出现的概率。

c o d e code code

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>

using namespace std;

const int MAXN = 1e2 + 10;

int n;
struct node {
	double x, y, p;
}a[MAXN];
double ans;

bool judge(double x, double y, double x1, double y1, double x2, double y2) {
	return (x - x2) * (y1 - y2) - (x1 - x2) * (y - y2) < 0;
}

int main() {
	freopen("polygons.in", "r", stdin);
	freopen("polygons.out", "w", stdout);
	scanf("%d", &n);
	for(int i = 1; i <= n; i ++) scanf("%lf%lf%lf", &a[i].x, &a[i].y, &a[i].p);
	for(int i = 1; i <= n; i ++)
		for(int j = 1; j <= n; j ++) {
			if(i == j) continue;
			double g = a[i].x * a[j].y - a[i].y * a[j].x;
			for(int k = 1; k <= n; k ++) {
				if(k == i || k == j) continue;
				if(judge(a[i].x, a[i].y, a[j].x, a[j].y, a[k].x, a[k].y)) g *= 1 - a[k].p;
			}
			ans += a[i].p * a[j].p * (g / 2);
		}
	printf("%.7lf", ans + 1e-8);
	return 0;
}
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值