计算几何,极角排序,双指针,二分。

直接找锐角三角形的个数不好找,可以通过反面来求解。

首先,$n$个点最多能组成三角形个数有$C_n^3$个,但是这之中还包括了直角三角形,钝角三角形,平角三角形,我们需要减去这些三角形的个数。

如果在$n$个点中找到了$A$个直角,那么必然有$A$个直角三角形。

同理,如果找到了$B$个钝角,那么必然有$B$个钝角三角形。

同理,如果找到了$C$个平角,那么必然有$C$个平角三角形。

那么答案:$ans=C_n^3-A-B-C$。

接下里的任务就是求解$A$,$B$,$C$的总和是多少。

计算$A+B+C$,可以枚举一个点$P$作为三角形顶点,然后剩余的点根据$P$点作为原点进行极角排序,然后进行尺取(或者二分)。

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-;
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
}
template <class T>
inline void read(T &x)
{
char c = getchar(); x = ;while(!isdigit(c)) c = getchar();
while(isdigit(c)) { x = x * + c - ''; c = getchar(); }
} const int MAX = ;
struct point{ LL x, y; }s[MAX],t[MAX];
int n; LL CrossProd(point p0, point p1, point p2){
return (p1.x-p0.x)*(p2.y-p0.y) - (p1.y-p0.y)*(p2.x-p0.x);
} bool cmp(const point &a, const point &b)
{
if (a.y == && b.y == && a.x*b.x <= ) return a.x>b.x;
if (a.y == && a.x >= && b.y != ) return true;
if (b.y == && b.x >= && a.y != ) return false;
if (b.y*a.y <= ) return a.y>b.y;
point one; one.y = one.x = ;
return CrossProd(one,a,b) > || (CrossProd(one,a,b) == && a.x < b.x);
} LL dis2(point a,point b)
{
return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
} bool check(point a,point b,point c)
{
LL lena=dis2(b,c);
LL lenb=dis2(a,c);
LL lenc=dis2(a,b);
if(lenb+lenc-lena<=) return ;
return ;
} int main()
{
while(~scanf("%d",&n))
{
for(int i=;i<=n;i++) scanf("%lld%lld",&t[i].x,&t[i].y);
LL ans=(LL)n*(LL)(n-)*(LL)(n-)/(LL); int sz;
for(int i=;i<=n;i++)
{
sz=;
for(int j=;j<=n;j++)
{
if(i==j) continue;
s[sz].x=t[j].x-t[i].x; s[sz].y=t[j].y-t[i].y;
sz++;
} sort(s,s+sz,cmp); for(int j=;j<sz;j++)
{
point tmp; tmp.x=; tmp.y=;
int L=j,R=sz-,pos=-;
while(L<=R)
{
int mid=(L+R)/;
if(CrossProd(tmp,s[j],s[mid])>=) L=mid+,pos=mid;
else R=mid-;
} if(pos!=-&&pos>=j+)
{
L=j+,R=pos; int h=-;
while(L<=R)
{
int mid=(L+R)/;
if(check(tmp,s[j],s[mid])) R=mid-, h=mid;
else L=mid+;
} if(h!=-) ans=ans-(LL)(pos-h+);
} if(pos!=-&&pos+<=sz-)
{
L=pos+,R=sz-; int h=-;
while(L<=R)
{
int mid=(L+R)/;
if(check(tmp,s[j],s[mid])) L=mid+, h=mid;
else R=mid-;
} if(h!=-) ans=ans-(LL)(h-pos);
}
}
}
printf("%lld\n",ans);
}
return ;
}

HDU 5784 How Many Triangles的更多相关文章

  1. hdu 5784 How Many Triangles 计算几何,平面有多少个锐角三角形

    How Many Triangles 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5784 Description Alice has n poin ...

  2. HDU 5784 (计算几何)

    Problem How Many Triangles (HDU 5784) 题目大意 给定平面上的n个点(n<2000),询问可以组成多少个锐角三角形. 解题分析 直接统计锐角三角形较困难,考虑 ...

  3. 美人鱼 hdu 5784

    Peter has a sequence a1,a2,...,ana1,a2,...,an and he define a function on the sequence -- F(a1,a2,.. ...

  4. [HDU 5135] Little Zu Chongzhi's Triangles (dfs暴搜)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5135 题目大意:给你n条边,选出若干条边,组成若干个三角形,使得面积和最大.输出最大的面积和. 先将边 ...

  5. hdu 1396 Counting Triangles(递推)

    Counting Triangles Problem Description Given an equilateral triangle with n thelength of its side, p ...

  6. hdu 5135 Little Zu Chongzhi's Triangles

    http://acm.hdu.edu.cn/showproblem.php?pid=5135 题意:给你N个木棍的长度,然后让你组成三角形,问你组成的三角形的和最大是多少? 思路:先求出可以组成的所有 ...

  7. HDUOJ-Counting Triangles

    Counting Triangles Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  8. 转载:hdu 题目分类 (侵删)

    转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...

  9. HDU 2018 Multi-University Training Contest 1 Triangle Partition 【YY】

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6300 Triangle Partition Time Limit: 2000/1000 MS (Java ...

随机推荐

  1. [转]HTTP请求模型和头信息参考

    [转]HTTP请求模型和头信息参考 参考: http://blog.csdn.net/baggio785/archive/2006/04/13/661410.aspx模型: http://blog.c ...

  2. C++中的结构体vector排序

    在包含了头文件#include <algorithm>之后,就可以直接利用sort函数对一个vector进行排序了: // sort algorithm example #include ...

  3. IIS配置 Web部署 svg/woff/woff2字体 404错误

    一,woff/woff2字体 404错误,这个可以在浏览器按F12的Console页面可以发现问题,如下图: 解决方法: 一,打开服务器IIS管理器,找到MIME类型 二,添加MIME类型 添加三条: ...

  4. 初步使用nodejs(一)

    初步使用nodejs(一) 首先打开 https://nodejs.org/,点击INSTALL下载安装 安装完成后 打开CMD 输入node –v 验证是否正常 至此,NODEJS安装完成. 下载W ...

  5. ECMAScript6之数值类型的扩展

    数值类型的扩展 Number.isNaN ES6将isNaN方法从window身上移植到了Number对象上,使用时和ES5中的isNaN方法一样,但是这是Number对象的方法 Number.isN ...

  6. Tiny6410之重定位代码到SRAM+4096

    重定位代码 两个不同的地址概念: 对于程序而言,需要理解两个地址,一个是程序当前所处的地址,即程序运行时所处的当前地址.二是程序应该位于的运行地址,即编译程序时所指定的程序的链接地址.在Tiny641 ...

  7. kali客户端攻击

    浏览器攻击 browser_autpwn2 (BAP2) mkdir /test 为接受响应的服务器创建目录   use auxiliary/server/browser_autopwn2  set ...

  8. Linq 内联左联等

    我们在做SQL查询的时候经常会用到Inner Join,Left Join,笛卡尔积等等,连接方式的概念方面我想也不用给予太多解释, 我们今天的重点是让大家熟悉LINQ是如何使用Join来实现常用的表 ...

  9. ansible 判断和循环

    标准循环 模式一 - name: add several users user: name={{ item }} state=present groups=wheel with_items: - te ...

  10. 从P1到P7——我在淘宝这7年(转)

    作者: 赵超  发布时间: 2012-02-25 14:47  阅读: 114607 次  推荐: 153   [收藏] (一) 2011-12-08 [原文链接] 今天有同事恭喜我,我才知道自己在淘 ...