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

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

首先,$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. URL传值问题,不同浏览器对URL的长度要求

    通过URL传值的问题,所以对url字符串进行encodeURIComponent对url字符串内容进行编码,问题解决,但是有时候会出现 The request filtering module is ...

  2. [UWP小白日记-9]页面跳转过度动画(二)

    又打算动手写了 [UWP小白日记-6]页面跳转过度动画 上次写的,这次随着学习的进度使用新的玩法. 最近在搞GIT的学习,结果把好好的项目玩坏,都不知道当时是怎么想的拿在写的APP来玩GIT,害我重写 ...

  3. JavaScript 中的this指向问题

    全局执行     首先,我们在全局环境中看看它的 this 是什么:     浏览器:     console.log(this);     // Window {speechSynthesis: S ...

  4. 遍历HashMap的最佳方式

    public static void printMap(Map mp) { Iterator it = mp.entrySet().iterator(); while (it.hasNext()) { ...

  5. Django回忆录

    Django使用回忆: 1.安装django: pip install django==1.9 2.创建项目及应用: django-admin startproject web django-admi ...

  6. 正则表达式之 match , findall, sub,subn

    #正则表达式之 match以及分组 import re #无分组 origin = "hello alex bcd alex lge alex avd 19" r = re.mat ...

  7. Salesforce自主学习(一)

    Salesforce学习--接触Apex: 学习目标: 1.描述出Apex程序语言的关键特点: 2.保存一个Apex类并用另一个Apex类来调用它的方法: 3.使用Developer Console检 ...

  8. CentOS 7上的性能监控工具

    Linux中基于命令行的性能监控工具:dstat.top.netstat.vmstat.htop.ss.glances 1.dstat – 多类型资源统计工具(需配置epel源) 该命令整合了vmst ...

  9. usaco 2.2.4 生日派对灯(最近写题碰到的,虽然知道现在写这个有点晚了)

    经过分析,他看似很多的开灯的方法其实合并起来就只有八个. 首先,一个开关在执行的时候只能按一次(因为你就算按了两次就相当于一次也没有按). 当一个都不按的时候  当然就只有一种:不按. 当按一下的时候 ...

  10. PXE+kickstart自动安装ubuntu14.04

    本文参考了诸多文章,先感谢这些文章的作者. 使用pxe安装系统需要安装dhcp,tftp,http等服务(当然也可以使用其他文件共享方式比如nfs,ftp). 实验环境: 1. vmware 12 2 ...