HDU 1071 - The area

本文介绍了一个简单的数学问题——如何计算特定条件下的阴影面积。通过给定的三个坐标点,利用数学公式计算二次函数与直线围成的阴影部分面积。代码使用 C++ 实现,并通过循环多次读取输入来解决多个实例问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

HDU 1071 - The area

Easy Math Problems -_-


Output the area of the shadow area.

The consuming key point exsists in how to caculate a, b, c.
kind of easy, as long as you just go ahead without considering the complexity of your expression.

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

using namespace std;
void fMain() {
	double x1, y1, x2, y2, x3, y3;
	double a, b, c, k, b1, s;
//y=a*x*x+b*x+c;
//y=k*x+b2;

	cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;

	k = (y3 - y2) / (x3 - x2);
	b1 = y3 - k * x3;

	a = ((x2 - x1) * (y3 - y2) - (x3 - x2) * (y2 - y1)) / ((pow(x3, 2) - pow(x2, 2)) * (x2 - x1) - (pow(x2, 2) - pow(x1, 2)) * (x3 - x2));
	b = ((y2 - y1) - a * (pow(x2, 2) - pow(x1, 2))) / (x2 - x1);
	c = y1 - a * pow(x1, 2) - b * x1;

	s = a / 3 * (pow(x3, 3) - pow(x2, 3)) + (b - k) / 2 * (pow(x3, 2) - pow(x2, 2)) + (c - b1) * (x3 - x2);
	printf("%.2lf\n", s);
}


int main() {
	int n;
	char temp;
	scanf("%d", &n);
	scanf("%c", &temp);
	while(n--) {
		fMain();
	}
}

。。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值