多校5 1004 HDU5784 统计锐角三角形数目
http://acm.hdu.edu.cn/showproblem.php?pid=5784
题意:n个点,找多少个锐角三角形数目
思路:极角排序+two pointers
当前选择的点集要倍增一倍,点集过大时,极角排序后,后面的点有可能和前面的点形成钝角
ans=总的三角形数目 - 三点共线的情况-直角和钝角
// #pragma comment(linker, "/STACK:102c000000,102c000000")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <string>
#include <algorithm>
#include <list>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
// #include <conio.h>
using namespace std;
#define clc(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
#define lson l,mid,rt<<1
// #define rson mid+1,r,rt<<1|1
const int N = ;
const int M = 1e6+;
const int MOD = 1e9+;
#define LL long long
#define LB long double
// #define mi() (l+r)>>1
double const pi = acos(-);
const double eps = 1e-;
void fre(){freopen("in.txt","r",stdin);}
inline int read(){int x=,f=;char ch=getchar();while(ch>''||ch<'') {if(ch=='-') f=-;ch=getchar();}while(ch>=''&&ch<='') { x=x*+ch-'';ch=getchar();}return x*f;} struct Point{
LL x,y;
Point(){}
Point(LL _x,LL _y):x(_x),y(_y){}
Point operator + (const Point &t)const{
return Point(x+t.x,y+t.y);
}
Point operator - (const Point &t)const{
return Point(x-t.x,y-t.y);
}
LL operator * (const Point &t)const{
return x*t.y-y*t.x;
}
LL operator ^ (const Point &t)const{
return x*t.x+y*t.y;
}
bool operator < (const Point &b)const{
if (y * 1LL * b.y <= ) {
if (y > || b.y > ) return y < b.y;
if (y == && b.y == ) return x < b.x;
}
return (*this)*b > ;
}
}p[N],v[N<<]; int main(){
int n;
while(~scanf("%d",&n)){
for(int i=;i<n;i++) scanf("%I64d%I64d",&p[i].x,&p[i].y);
LL ans=1LL*n*(n-)*(n-)/,tem=;
for(int k=;k<n;k++){
int cnt=;
for(int i=;i<n;i++){
if(k==i)continue;
v[cnt++]=p[i]-p[k];
}
sort(v,v+cnt);
for(int i=;i<cnt;i++) v[i+cnt]=v[i];
int cxt=;
for(int i=;i<cnt;i++){
if(v[i-]*v[i]==&&(v[i-]^v[i])>) cxt++;
else cxt=;
tem+=cxt;
}
for(int i=,p1=,p2=;i<cnt;i++){
while(p1<=i||(p1<i+cnt&&v[p1]*v[i]<&&(v[p1]^v[i])>)) p1++;
while(p2<=i||(p2<i+cnt&&v[p2]*v[i]<)) p2++;
ans-=p2-p1;
}
}
printf("%I64d\n",ans-tem/);
}
return ;
}
多校5 1004 HDU5784 统计锐角三角形数目的更多相关文章
- HDU 4669 Mutiples on a circle (2013多校7 1004题)
Mutiples on a circle Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Oth ...
- HDU 4699 Editor (2013多校10,1004题)
Editor Time Limit: 3000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Su ...
- HDU 4679 Terrorist’s destroy (2013多校8 1004题 树形DP)
Terrorist’s destroy Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Othe ...
- HDU 4658 Integer Partition (2013多校6 1004题)
Integer Partition Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- Linux统计文件数目
统计当前目录下文件数目 $ find . -type f | wc -l 统计文件行数 $ wc -l filename 仅统计内容为pattern的行(只有pattern) $ grep -w &q ...
- C语言实现二叉树-利用二叉树统计单词数目
昨天刚参加了腾讯2015年在线模拟考: 四道大题的第一题就是单词统计程序的设计思想: 为了记住这一天,我打算今天通过代码实现一下: 我将用到的核心数据结构是二叉树: (要是想了解简单二叉树的实现,可以 ...
- MapReduce流程、如何统计任务数目以及Partitioner
核心功能描述 应用程序通常会通过提供map和reduce来实现 Mapper和Reducer接口,它们组成作业的核心. Map是一类将输入记录集转换为中间格式记录集的独立任务. 这种转换的中间格式记录 ...
- Linux 命令 统计进程数目
ps -efL | grep python | wc -l 此命令的意思是查看 Python的进程数目 ps -ef|grep python|grep -v grep|cut -c -|xargs k ...
- HDU 4635 Strongly connected (2013多校4 1004 有向图的强连通分量)
Strongly connected Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
随机推荐
- 开发版本控制git
git init 在git命令行中依次输入 touch readme.txt并回车, git add . 点代表所有, git commit -m "init first"并回车, ...
- java:访问权限-protected实例
在不同包,子类继承后可以使用父类的protect权限的属性或方法 父类: package com.tinyphp; public class Father { protected String nam ...
- C++:基类和派生类
4.1 派生类的声明 继承实例如下: class Person{ //声明基类Person public: void print() { cout<<"name:"&l ...
- 7、单向一对多的关联关系(1的一方有n的一方的集合属性,n的一方却没有1的一方的引用)
单向一对多的关联关系 具体体现:1的一方有n的一方的集合的引用,n的一方却没有1的一方的引用 举个例子:顾客Customer对订单Order是一个单向一对多的关联关系.Customer一方有对Orde ...
- 1、搭建springMVC开发环境以及HelloWorld测试
一.下载spring-framework,采用简单的方式: http://repo.springsource.org/libs-release-local/org/springframework/sp ...
- shell编程基础(5)---循环指令
while类型的循环 while类型的循环是不定循环的一种,每一次循环都会验证给出的循环条件,判断是否要进行下一次循环.linux中while循环的写法和c语言中很想,但是条件给出的方式有些区别. 首 ...
- 一行很好的JS代码
[].forEach.call($$("*"),function(a){ a.style.outline="1px solid #"+(~~(Math.rand ...
- Javascript如何判断一个变量是数字类型?
isNaN()不能判断一个变量是否为数字类型,isNaN(123)值为false,isNaN('123')值也为false.isNaN() 的实际作用跟它的名字isNaN并不一致,isNaN(NaN) ...
- 在XML里的XSD和DTD以及standalone的使用3----具体使用详解
本人亲自写的一个简单的测试例子 1.xsd定义 <?xml version="1.0" encoding="utf-8"?><xs:schem ...
- 添加gif效果图
1.贴加第三方包 http://blog.csdn.net/iamlazybone/article/details/5972234 2. <FrameLayout android:id=&quo ...