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

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

首先,$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. (转载)python日期函数

    转载于http://www.cnblogs.com/emanlee/p/4399147.html 所有日期.时间的api都在datetime模块内. 1. 日期输出格式化 datetime => ...

  2. jsp Ajax请求(返回json数据类型)

    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"% ...

  3. Intellj idea 安装JUnit

    1.file-Settings-Plugins-Browse repositories-HTTP Proxy Settings将No proxy改成Auto-detect proxy settings ...

  4. jsp页面根据当前时间和定义时间差计算动态倒计时

    jsp页面根据当前时间和定义时间差计算动态倒计时http://www.jb51.net/article/74140.htm    var maxtime =1000*60; //半个小时,按秒计算,自 ...

  5. OBIEE接受外部参数

    样例: http://192.168.0.99/analytics/saw.dll?Go&Path=/shared/goxiangyibiaopan/SBDW_GSYDL_ZZT&Ac ...

  6. AFURLRequestSerialization

    NSString * AFPercentEscapedStringFromString(NSString *string)   //去除非法字符并且对特殊字符进行编码.  //对字符串进行百分比编码 ...

  7. 【ARM】S5PV210芯片的启动流程

    S5PV210芯片的设计者的思想 (1)芯片启动后执行iRom(BL0)的内容,进行时钟和看门狗等外设的初始化,将BL1和BL2拷贝到片内SRAM; (2)跳转到片内SRAM执行,完成外部SDRAM的 ...

  8. C++的第一天

    第一次写博客,第一天的C++,从第一讲视屏中了解到了,类,对象,oop编程思想 1.类包括对象和对象的行为,对象具有静态连接(对象的名字)和动态链接(对象的行为),视屏中提到了多态性,应该是不同的类具 ...

  9. table表头thead固定

    <html> <head> <meta charset="utf-8"/> <script type="text/javascr ...

  10. Spring Security(17)——基于方法的权限控制

    目录 1.1     intercept-methods定义方法权限控制 1.2     使用pointcut定义方法权限控制 1.3     使用注解定义方法权限控制 1.3.1    JSR-25 ...