FZU2110 Star——————简单题

本文介绍了一种算法,用于解决给定点集时如何找出所有可能形成的锐角三角形数量的问题。通过计算点积判断角度类型,实现了快速有效的解决方案。

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

Star

Accept: 1174 Submit: 3553
Time Limit: 1000 mSec Memory Limit : 32768 KB

Problem Description

Overpower often go to the playground with classmates. They play and chat on the playground. One day, there are a lot of stars in the sky. Suddenly, one of Overpower’s classmates ask him: “How many acute triangles whose inner angles are less than 90 degrees (regarding stars as points) can be found? Assuming all the stars are in the same plane”. Please help him to solve this problem.
Input
The first line of the input contains an integer T (T≤10), indicating the number of test cases.

For each test case:

The first line contains one integer n (1≤n≤100), the number of stars.

The next n lines each contains two integers x and y (0≤|x|, |y|≤1,000,000) indicate the points, all the points are distinct.

Output
For each test case, output an integer indicating the total number of different acute triangles.
Sample Input
1
3
0 0
10 0
5 1000
Sample Output
1
Source
“高教社杯”第三届福建省大学生程序设计竞赛


给你一些点,让你找出三个点,求找出三个点组成的三角形是锐角三角形的个数(方案数)

简单题,计算下两条边的点积,若点积大于0就说明这里两条边的夹角是锐角

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;

struct P{
	ll x,y;
	
}p[105];

ll dot(P A, P B, P C)//求AB与AC的点积
{
	P AB, AC;
	AB.x = B.x-A.x;
	AB.y = B.y-A.y;
	AC.x = C.x-A.x;
	AC.y = C.y-A.y;
//	prllf("(%d,%d)*(%d,%d) ",AB.x,AB.y,AC.x,AC.y);
	return AB.x*AC.x+AB.y*AC.y;
}

int main()
{
	ll t,n,x,y;
	cin>>t;
	while(t--)
	{
		cin>>n;
		for(ll i=0;i<n;++i)
			cin>>p[i].x>>p[i].y;
		ll ans = 0;
		for(ll i=0;i<n;++i)//A
			for(ll j=i+1;j<n;++j)//B
				for(ll k=j+1;k<n;++k)//C	AB*AC>0 && BA*BC>0 && CA*CB>0
				{
					if(dot(p[i],p[j],p[k])>0 && dot(p[j],p[i],p[k])>0 &&dot(p[k],p[i],p[j])>0)
						ans ++;
				}
		cout<<ans<<endl;
	}
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值