HDU 5784 How Many Triangles
计算几何,极角排序,双指针,二分。
直接找锐角三角形的个数不好找,可以通过反面来求解。
首先,$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的更多相关文章
- hdu 5784 How Many Triangles 计算几何,平面有多少个锐角三角形
How Many Triangles 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5784 Description Alice has n poin ...
- HDU 5784 (计算几何)
Problem How Many Triangles (HDU 5784) 题目大意 给定平面上的n个点(n<2000),询问可以组成多少个锐角三角形. 解题分析 直接统计锐角三角形较困难,考虑 ...
- 美人鱼 hdu 5784
Peter has a sequence a1,a2,...,ana1,a2,...,an and he define a function on the sequence -- F(a1,a2,.. ...
- [HDU 5135] Little Zu Chongzhi's Triangles (dfs暴搜)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5135 题目大意:给你n条边,选出若干条边,组成若干个三角形,使得面积和最大.输出最大的面积和. 先将边 ...
- hdu 1396 Counting Triangles(递推)
Counting Triangles Problem Description Given an equilateral triangle with n thelength of its side, p ...
- hdu 5135 Little Zu Chongzhi's Triangles
http://acm.hdu.edu.cn/showproblem.php?pid=5135 题意:给你N个木棍的长度,然后让你组成三角形,问你组成的三角形的和最大是多少? 思路:先求出可以组成的所有 ...
- HDUOJ-Counting Triangles
Counting Triangles Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- 转载:hdu 题目分类 (侵删)
转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...
- 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 ...
随机推荐
- 蓝桥杯 C语言 入门训练 序列求和
问题描述 求1+2+3+...+n的值. 输入格式 输入包括一个整数n. 输出格式 输出一行,包括一个整数,表示1+2+3+...+n的值. 样例输入 4 样例输出 10 样例输入 100 说明:有一 ...
- Activity和Fragment之间解耦
看鸿洋博客:http://blog.csdn.net/lmj623565791/article/details/42628537,整理下一些关键点 public class ContentFragme ...
- [HMLY]11.iOS函数式编程的实现&&响应式编程概念
简介 本篇主要回顾一下--iOS函数式编程 && 响应式编程概念 ,如何一步步实现函数式编程的过程,对阅读Masonry && SnapKit源码有一定的帮助. 作为一 ...
- JSON对象和字符串的转换
JSON.parse()和JSON.stringify() 1.parse 用于从一个字符串中解析出json 对象.例如 var str='{"name":"cpf& ...
- codevs1069关押罪犯(并查集)
题目描述 Description S 城现有两座监狱,一共关押着N 名罪犯,编号分别为1~N.他们之间的关系自然也极 不和谐.很多罪犯之间甚至积怨已久,如果客观条件具备则随时可能爆发冲突.我们用“怨 ...
- 使用Redis的Java客户端Jedis
转载自:http://aofengblog.blog.163.com/blog/static/631702120147298317919/ 前一篇文章<Redis命令指南>讲解了通过命令行 ...
- java方法笔记
1.方法 方法(method),函数(function)//但本质上是一样的--实现特定的功能.程序中完成独立功能,可重复使用的一段代码的集合:方法的格式:[修饰符] 返回值的类型 方法名称([形式参 ...
- winServer2008下安装SqlServer2008数据库
1 安装文件包 文件名 cn_sql_server_2008_r2_enterprise_x86_x64_ia64_dvd_522233.iso SHA1 0EEFF017B21635DF33F33C ...
- Codeforces Round #390 (Div. 2)
时隔一个月重返coding…… 期末复习了一个月也不亏 倒是都过了…… 就是计组61有点亏 复变68也太低了 其他都还好…… 假期做的第一场cf 三道题 还可以…… 最后room第三 standing ...
- nginx使用openssl的证书-泛解析
一.需求分析 我们公司测试环境,域名更换,原来的*.dev.devbao.cn 变为 *.dev.vdai.cn ,此处的*表示多个二级域名,导致原来为dev.devbao.cn制作的ssl ...