hdu5120——Intersection

Intersection

Time Limit: 4000/4000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java/Others)
Total Submission(s): 119    Accepted Submission(s): 49


Problem Description
Matt is a big fan of logo design. Recently he falls in love with logo made up by rings. The following figures are some famous examples you may know.


A ring is a 2-D figure bounded by two circles sharing the common center. The radius for these circles are denoted by r and R (r < R). For more details, refer to the gray part in the illustration below.


Matt just designed a new logo consisting of two rings with the same size in the 2-D plane. For his interests, Matt would like to know the area of the intersection of these two rings.
 

Input
The first line contains only one integer T (T ≤ 10 5), which indicates the number of test cases. For each test case, the first line contains two integers r, R (0 ≤ r < R ≤ 10).

Each of the following two lines contains two integers x i, y i (0 ≤ x i, y i ≤ 20) indicating the coordinates of the center of each ring.
 

Output
For each test case, output a single line “Case #x: y”, where x is the case number (starting from 1) and y is the area of intersection rounded to 6 decimal places.
 

Sample Input
  
2 2 3 0 0 0 0 2 3 0 0 5 0
 

Sample Output
  
Case #1: 15.707963 Case #2: 2.250778
 

Source
 

Recommend

圆环相交 --->大圆交大圆(如果相交) - 2 * 大圆交小圆 (如果相交) + 小圆交小圆(如果相交)

重现赛不知道哪里写错了一直WA,赛后推翻重写就AC了

#include <map>
#include <set>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

const double pi = acos(-1);
struct point
{
	double x, y;
};

double calc_area(point a, point b, double r1, double r2)
{
	double d = sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
	if (r1 - r2 - d >= 0)
	{
		return pi * r2 * r2;
	}
	double ang1 = acos((r1 * r1 + d * d - r2 * r2) / (2 * r1 * d));
	double ang2 = acos((r2 * r2 + d * d - r1 * r1) / (2 * r2 * d));
	return ang1 * r1 * r1 + ang2 * r2 * r2 - 0.5 * r1 * d * sin(ang1) - 0.5 * r2 * d * sin(ang2);
}

int main()
{
	int t, icase = 1;
	scanf("%d", &t);
	while (t--)
	{
		double r, R, ans = 0;
		point p1, p2;
		scanf("%lf%lf", &r, &R);
		scanf("%lf%lf", &p1.x, &p1.y);
		scanf("%lf%lf", &p2.x, &p2.y);
		double d = sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y));
		printf("Case #%d: ", icase++);
		if (d >= (2 * R))
		{
			printf("0.000000\n");
			continue;
		}
		ans = calc_area(p1, p2, R, R);
		if (d >= (R + r))
		{
			printf("%f\n", ans);
			continue;
		}
		ans -= 2 * calc_area(p1, p2, R, r);
		if (d >= (2 * r))
		{
			printf("%f\n", ans);
			continue;
		}
		ans += calc_area(p1, p2, r, r);
		printf("%f\n", ans);
	}
	return 0;
}


内容概要:本文档详细介绍了一个基于MATLAB实现的电力负荷预测项目,该项目运用遗传算法(GA)优化支持向量回归(SVR)和支持向量机(SVM)模型的超参数及特征选择。项目旨在解决电力系统调度、发电计划、需求侧响应等多个应用场景中的关键问题,特别是在应对高比例可再生能源接入带来的非线性、非平稳负荷预测挑战。文中涵盖了从数据接入、特征工程、模型训练到部署上线的全流程,包括详细的代码示例和GUI设计,确保方案的可复现性和实用性。 适用人群:具备一定编程基础,尤其是熟悉MATLAB语言和机器学习算法的研发人员;从事电力系统调度、电力市场交易、新能源消纳等相关领域的工程师和技术专家。 使用场景及目标:①通过构建面向小时级别的滚动预测,输出高分辨率负荷轨迹,为日内与日前滚动调度提供边际成本最小化的依据;②在负荷高峰和供给紧张时,通过价格信号或直接负荷控制实施需求侧响应,提升削峰效率并抑制反弹;③为灵活性资源(调峰机组、储能、可中断负荷)提供更清晰的出清路径,降低弃风弃光率,提升系统整体清洁度;④帮助市场主体更准确地评估边际出清价格变化,提高报价成功率与收益稳定性,同时降低由预测偏差带来的风险敞口;⑤在运维与审计场景中,对预测产生的原因进行说明,保障业务侧与监管侧的可追溯性。 阅读建议:此资源不仅提供了完整的代码实现和GUI设计,更注重于理解GA优化过程中涉及到的数据处理、特征构造、模型选择及评估等核心步骤。因此,在学习过程中,建议结合实际案例进行实践,并深入研究每个阶段的具体实现细节,特别是适应度函数的设计、超参数空间的定义以及多样性维护机制的应用。此外,关注项目中关于数据对齐、缺失值处理、特征标准化等方面的最佳实践,有助于提高模型的鲁棒性和泛化能力。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值