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

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

后来应该是因为精度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 <iostream>
#include <algorithm>
#include <cstring> #include <cstdio> #include <cmath> using namespace std;
#define PI 3.1415926
#define EPS 1.0e-6 struct 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)<EPS) return 0; return 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<<getAngle(star[i], star[j], star[k])<<endl;
if(sharpTri(star[i], star[j], star[k])) cnt++;
}
}
}
cout<<cnt<<endl;
} return 0; }

FZU2110 Star【计算几何】的更多相关文章

  1. POJ 2420 A Star not a Tree? (计算几何-费马点)

    A Star not a Tree? Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3435   Accepted: 172 ...

  2. POJ 2069 Super Star(计算几何の最小球包含+模拟退火)

    Description During a voyage of the starship Hakodate-maru (see Problem 1406), researchers found stra ...

  3. [转] POJ计算几何

    转自:http://blog.csdn.net/tyger/article/details/4480029 计算几何题的特点与做题要领:1.大部分不会很难,少部分题目思路很巧妙2.做计算几何题目,模板 ...

  4. ACM计算几何题目推荐

    //第一期 计算几何题的特点与做题要领: 1.大部分不会很难,少部分题目思路很巧妙 2.做计算几何题目,模板很重要,模板必须高度可靠. 3.要注意代码的组织,因为计算几何的题目很容易上两百行代码,里面 ...

  5. 【Star CCM+实例】开发一个简单的计算流程.md

    流程开发在CAE过程中处于非常重要的地位. 主要的作用可能包括: 将一些经过验证的模型隐藏在流程中,提高仿真的可靠性 将流程封装成更友好的界面,降低软件的学习周期 流程开发实际上需要做非常多的工作,尤 ...

  6. github中的watch、star、fork的作用

    [转自:http://www.jianshu.com/p/6c366b53ea41] 在每个 github 项目的右上角,都有三个按钮,分别是 watch.star.fork,但是有些刚开始使用 gi ...

  7. [deviceone开发]-Star分享的几个示例

    一.简介 这个是star早期分享的几个示例,都非常实用,包括弹出的菜单,模拟支付密码输入等.初学者推荐.也可以直接使用.二.效果图 三.相关下载 https://github.com/do-proje ...

  8. 时隔一年再读到the star

    The Star Arthur C. Clarke It is three thousand light-years to the Vatican. Once, I believed that spa ...

  9. Github上的Watch和 Star的区别

    Github 推出了新的 Notification 系统,更改了原有的 Watch 机制,为代码库增加了 Star 操作.Notification 将接收 Watching 代码库的动态,包括:* I ...

随机推荐

  1. python 字符串格式化,使用f前缀

    格式化一般用%,但后来推荐用format format有进步,可以用索引或者名字,但仍然没有很方便和快捷 # logger.debug('{} {} {} {} {} {}'.format(metho ...

  2. python--内置函数---13

    原创博文,转载请标明出处--周学伟 http://www.cnblogs.com/zxouxuewei/ Python 内置函数     内置函数     abs() divmod() input() ...

  3. Java -- 异常的捕获及处理 -- 目录

    7 异常的捕获及处理 7.1 异常的基本概念 7.1.1 为什么需要异常处理 7.1.2 在程序中使用异常处理 7.1.3 异常类的继承结构 7.1.4 Java的异常处理机制 7.2 throws与 ...

  4. express安装及使用(windows系统)

    npm install express //安装express命令 npm install express-generator -g //Express 应用生成器,通过应用生成器工具 express ...

  5. 执行RF设置顶级测试套件的名称

    场景1:通过pybot进行单个output文件情况下设置 -N --name name 设置顶级测试套件的名称.名称中的下划线将转换为空格. 默认名称为执行的数据源的名称. 场景2:通过rebot进行 ...

  6. shell中判断是否是月末的方法

    判断今天是不是一月的最后一天: 如果$(TZ=IST-32 date +%d)是1就是月末了.

  7. Elasticsearch 版本控制

    悲观并发控制(Pessimistic concurrency control) 这在关系型数据库中被广泛的使用,假设冲突的更改经常发生,为了解决冲突我们把访问区块化.典型的例子是在读一行数据前锁定这行 ...

  8. C#实现新建文件并写入内容

    using System; using System.IO; namespace ConsoleApplication1 { class Program { static void Main(stri ...

  9. MVC C# JS根据后台传入对象设置

    今天(20170401)在借鉴代码的时候,看到如下一串 @if (Model.Product.ID > 0) { <script> $(function () { setSpecLi ...

  10. Delphi应用程序的调试(四)The Debug Inspector

    调试检查器(The Debug Inspector) Debug Inspector使用户能查看诸如类和记录的数据对象,也可以用它来查看整数.字符数组等简单数据类型,但这类简单数据类型最好是用Watc ...