HDU 3340 Rain in ACStar(线段树+几何)

本文详细解析了HDU3340 Rain in ACStar问题的解决方案,通过将多边形切割为梯形并使用线段树进行高效计算,实现了对区间内多边形总面积的有效查询。

HDU 3340 Rain in ACStar

题目链接

题意:给定几个多边形(3-5边形),然后中间有一些询问。询问一个区间的总面积

思路:多边形切割为梯形,梯形的面积为上底d1 + 下底d2 乘上 高度 / 2。两个梯形面积累加的话,能够等价为上底下底累加,所以就能够用线段树搞了,然后给定的多边形点是按顺序的,能够利用容斥去方便把一个询问拆分成几个询问

代码:

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;

const int N = 133333;
int t, n;

struct Point {
	int x, y, id;
	Point() {}
	Point(int x, int y) {
		this->x = x;
		this->y = y;
		this->id = id;
	}
	void read() {
		scanf("%d%d", &x, &y);
	}
} p[6];

bool cmpp(Point a, Point b) {
	return a.x < b.x;
}

struct OP {
	int tp, l, r;
	double a, b;
	OP() {}
	OP(int l, int r, int tp, double a = 0.0, double b = 0.0) {
		this->l = l; this->r = r; this->tp = tp;
		this->a = a; this->b = b;
	}
} op[N];

int hash[N * 2], hn, opn;

int find(int x) {
	return lower_bound(hash, hash + hn, x) - hash;
}

void build_p(int m) {
	p[m++] = p[0];
	for (int i = 0; i < m - 1; i++) {
		if (p[i].x < p[i + 1].x) op[opn++] = OP(p[i].x, p[i + 1].x, 1, -p[i].y, -p[i + 1].y);
		else op[opn++] = OP(p[i + 1].x, p[i].x, 1, p[i + 1].y, p[i].y);
	}
}

#define lson(x) ((x<<1)+1)
#define rson(x) ((x<<1)+2)

struct Node {
	int l, r;
	double d1, d2, s;
	void gao(double a, double b) {
		d1 += a;
		d2 += b;
		s += (a + b) * (hash[r + 1] - hash[l]) / 2;
	}
} node[N * 8];

void build(int l, int r, int x = 0) {
	node[x].l = l; node[x].r = r;
	node[x].d1 = node[x].d2 = node[x].s = 0;
	if (l == r) return;
	int mid = (l + r) / 2;
	build(l, mid, lson(x));
	build(mid + 1, r, rson(x));
}

double cal(double h1, double h2, double d1, double d2) {
	return (d2 * h1 + d1 * h2) / (h1 + h2);
}

void pushdown(int x) {
	double h1 = hash[node[lson(x)].r + 1] - hash[node[lson(x)].l];
	double h2 = hash[node[rson(x)].r + 1] - hash[node[rson(x)].l];
	double d = cal(h1, h2, node[x].d1, node[x].d2);
	node[lson(x)].gao(node[x].d1, d);
	node[rson(x)].gao(d, node[x].d2);
	node[x].d1 = node[x].d2 = 0;
}

void pushup(int x) {
	node[x].s = node[lson(x)].s + node[rson(x)].s;
}

void add(int l, int r, double a, double b, int x = 0) {
	if (node[x].l >= l && node[x].r <= r) {
		double d1 = cal(hash[node[x].l] - hash[l], hash[r + 1] - hash[node[x].l], a, b);
		double d2 = cal(hash[node[x].r + 1] - hash[l], hash[r + 1] - hash[node[x].r + 1], a, b);
		node[x].gao(d1, d2);
		return;
	}
	int mid = (node[x].l + node[x].r) / 2;
	pushdown(x);
	if (l <= mid) add(l, r, a, b, lson(x));
	if (r > mid) add(l, r, a, b, rson(x));
	pushup(x);
}

double query(int l, int r, int x = 0) {
	if (node[x].l >= l && node[x].r <= r) return node[x].s;
	int mid = (node[x].l + node[x].r) / 2;
	double ans = 0;
	pushdown(x);
	if (l <= mid) ans += query(l, r, lson(x));
	if (r > mid) ans += query(l, r, rson(x));
	pushup(x);
	return ans;
}

int main() {
	scanf("%d", &t);
	while (t--) {
		scanf("%d", &n);
		char ss[15];
		int l, r, m;
		hn = opn = 0;
		while (n--) {
			scanf("%s", ss);
			if (ss[0] == 'Q') {
				scanf("%d%d", &l, &r);
				hash[hn++] = l; hash[hn++] = r;
				op[opn++] = OP(l, r, 0);
			}
			else {
				scanf("%d", &m);
				for (int i = 0; i < m; i++) {
					p[i].read();
					hash[hn++] = p[i].x;
				}
				build_p(m);
			}
		}
		int tmp = 1;
		sort(hash, hash + hn);
		for (int i = 1; i < hn; i++)
			if (hash[i] != hash[i - 1])
				hash[tmp++] = hash[i];
		hn = tmp;
		build(0, hn - 2);
		for (int i = 0; i < opn; i++) {
			if (op[i].tp) add(find(op[i].l), find(op[i].r) - 1, op[i].a, op[i].b);
			else printf("%.3lf\n", query(find(op[i].l), find(op[i].r) - 1));
		}
	}
	return 0;
}


一、数据采集层:多源人脸数据获取 该层负责从不同设备 / 渠道采集人脸原始数据,为后续模型训练与识别提供基础样本,核心功能包括: 1. 多设备适配采集 实时摄像头采集: 调用计算机内置摄像头(或外接 USB 摄像头),通过OpenCV的VideoCapture接口实时捕获视频流,支持手动触发 “拍照”(按指定快捷键如Space)或自动定时采集(如每 2 秒采集 1 张),采集时自动框选人脸区域(通过Haar级联分类器初步定位),确保样本聚焦人脸。 支持采集参数配置:可设置采集分辨率(如 640×480、1280×720)、图像格式(JPG/PNG)、单用户采集数量(如默认采集 20 张,确保样本多样性),采集过程中实时显示 “已采集数量 / 目标数量”,避免样本不足。 本地图像 / 视频导入: 支持批量导入本地人脸图像文件(支持 JPG、PNG、BMP 格式),自动过滤非图像文件;导入视频文件(MP4、AVI 格式)时,可按 “固定帧间隔”(如每 10 帧提取 1 张图像)或 “手动选择帧” 提取人脸样本,适用于无实时摄像头场景。 数据集对接: 支持接入公开人脸数据集(如 LFW、ORL),通过预设脚本自动读取数据集目录结构(按 “用户 ID - 样本图像” 分类),快速构建训练样本库,无需手动采集,降低系统开发与测试成本。 2. 采集过程辅助功能 人脸有效性校验:采集时通过OpenCV的Haar级联分类器(或MTCNN轻量级模型)实时检测图像中是否包含人脸,若未检测到人脸(如遮挡、侧脸角度过大),则弹窗提示 “未识别到人脸,请调整姿态”,避免无效样本存入。 样本标签管理:采集时需为每个样本绑定 “用户标签”(如姓名、ID 号),支持手动输入标签或从 Excel 名单批量导入标签(按 “标签 - 采集数量” 对应),采集完成后自动按 “标签 - 序号” 命名文件(如 “张三
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值