博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
FZU2110 Star【计算几何】
阅读量:5139 次
发布时间:2019-06-13

本文共 3957 字,大约阅读时间需要 13 分钟。

 

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

130 010 05 1000

Sample Output

1

 

 

 

本来想用算夹角的函数的,还特意去找了一下模板

后来应该是因为精度WA了

才发现其实只用判断一下边之间的关系就可以判断是不是锐角三角形了

emmm题目的意思还要学会转换

 

判断锐角三角形:

A^2 + B^2 < C^2 就是锐角三角形

算夹角的模板:【没有精度判断】

 

double getAngle(Point p1, Point p2, Point p3){    double angle = 0.0;    Point va, vb;    va.x = p2.x - p1.x;    va.y = p2.y - p1.y;    vb.x = p3.x - p1.x;    vb.y = p3.y - p1.y;    double productValue = va.x * vb.x + va.y * vb.y;    double vaVal = sqrt(va.x * va.x + va.y * va.y);    double vbVal = sqrt(vb.x * vb.x + vb.y * vb.y);    double cosVal = productValue / (vaVal * vbVal);    if(cosVal < -1 && cosVal > -2){        cosVal = -1;    }    else if(cosVal > 1 && cosVal < 2){        cosVal = 1;    }    angle = acos(cosVal) * 180 / PI;    return angle;}

 

 

 

#include 
#include
#include
#include
#include
using namespace std;#define PI 3.1415926#define EPS 1.0e-6struct Point { Point(){} Point(double x, double y):x(x), y(y){} double x,y;};struct Line{ Point st, ed;};double getAngle(Point p1, Point p2, Point p3){ double angle = 0.0; Point va, vb; va.x = p2.x - p1.x; va.y = p2.y - p1.y; vb.x = p3.x - p1.x; vb.y = p3.y - p1.y; double productValue = va.x * vb.x + va.y * vb.y; double vaVal = sqrt(va.x * va.x + va.y * va.y); double vbVal = sqrt(vb.x * vb.x + vb.y * vb.y); double cosVal = productValue / (vaVal * vbVal); if(cosVal < -1 && cosVal > -2){ cosVal = -1; } else if(cosVal > 1 && cosVal < 2){ cosVal = 1; } angle = acos(cosVal) * 180 / PI; return angle;}int dblcmp(double r) { if(fabs(r)
0?1:-1;}double cross(Point p1, Point p2, Point p3, Point p4){ return (p2.x - p1.x) * (p4.y - p3.y) - (p2.y - p1.y) * (p4.x - p3.x);}double area(Point p1, Point p2, Point p3){ return cross(p1, p2, p1, p3);}double farea(Point p1, Point p2, Point p3){ return fabs(area(p1, p2, p3));}bool meet(Point p1, Point p2, Point p3, Point p4){ return max(min(p1.x, p2.x), min(p3.x, p4.x)) <= min(max(p1.x, p2.x), max(p3.x, p4.x)) && max(min(p1.y, p2.y), min(p3.y, p4.y)) <= min(max(p1.y, p2.y), max(p3.y, p4.y)) && dblcmp(cross(p3, p2, p3, p4) * cross(p3, p4, p3, p1)) >= 0 && dblcmp(cross(p1, p4, p1, p2) * cross(p1, p2, p1, p3)) >= 0;}Point inter(Point p1, Point p2, Point p3, Point p4){ double k = farea(p1, p2, p3) / farea(p1, p2, p4); return Point((p3.x + k * p4.x) / (1 + k), (p3.y + k * p4.y) / (1 + k));}bool sharpTri(Point p1, Point p2, Point p3){ double edge[3]; edge[0] = (p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y); edge[1] = (p1.x - p3.x) * (p1.x - p3.x) + (p1.y - p3.y) * (p1.y - p3.y); edge[2] = (p2.x - p3.x) * (p2.x - p3.x) + (p2.y - p3.y) * (p2.y - p3.y); sort(edge, edge + 3); if(edge[2] < edge[1] + edge[0] + EPS){ return true; } else return false;}int n;Point star[105];int main() { int t; cin>>t; while(t--){ scanf("%d", &n); for(int i = 0; i < n; i++){ scanf("%lf%lf", &star[i].x, &star[i].y); } int cnt = 0; for(int i = 0; i < n - 2; i++){ for(int j = i + 1; j < n - 1; j++){ for(int k = j + 1; k < n; k++){ //cout<

 

转载于:https://www.cnblogs.com/wyboooo/p/9643414.html

你可能感兴趣的文章
观察者模式
查看>>
Hadoop分布式文件系统中架构和设计要点汇总
查看>>
cout和printf
查看>>
UVa 10088 - Trees on My Island (pick定理)
查看>>
#C++PrimerPlus# Chapter11_Exersice4_mytimeV4
查看>>
iOS8 针对开发者所拥有的新特性汇总如下
查看>>
Jmeter + Grafana搭建实时监控可视化
查看>>
uCGUI字符串显示过程分析和uCGUI字库的组建
查看>>
h5唤起app
查看>>
SQL Server 2008 /SQL Server 2008 R2 配置数据库邮件
查看>>
[转]vs2010编译金山代码
查看>>
数学图形之Boy surface
查看>>
处理程序“PageHandlerFactory-Integrated”在其模块列表中有一个错误模块“Manag
查看>>
3.浏览器检测
查看>>
01: socket模块
查看>>
Border-radius
查看>>
mysql触发器
查看>>
Redis学习笔记(1)Redis安装和启动
查看>>
淌淌淌
查看>>
BZOJ1002:[FJOI2007]轮状病毒
查看>>