多校2016 1004 HDU5784 统计锐角三角形数目

http://acm.hdu.edu.cn/showproblem.php?pid=5784

题意:n个点,找多少个锐角三角形数目

思路:极角排序+two pointers

当前选择的点集要倍增一倍,点集过大时,极角排序后,后面的点有可能和前面的点形成钝角

ans=总的三角形数目 - 三点共线的情况-直角和钝角

 1 // #pragma comment(linker, "/STACK:102c000000,102c000000")
 2 #include <iostream>
 3 #include <cstdio>
 4 #include <cstring>
 5 #include <sstream>
 6 #include <string>
 7 #include <algorithm>
 8 #include <list>
 9 #include <map>
10 #include <vector>
11 #include <queue>
12 #include <stack>
13 #include <cmath>
14 #include <cstdlib>
15 // #include <conio.h>
16 using namespace std;
17 #define clc(a,b) memset(a,b,sizeof(a))
18 #define inf 0x3f3f3f3f
19 #define lson l,mid,rt<<1
20 // #define rson mid+1,r,rt<<1|1
21 const int N = 2010;
22 const int M = 1e6+10;
23 const int MOD = 1e9+7;
24 #define LL long long
25 #define LB long double
26 // #define mi() (l+r)>>1
27 double const pi = acos(-1);
28 const double eps = 1e-8;
29 void fre(){freopen("in.txt","r",stdin);}
30 inline int read(){int x=0,f=1;char ch=getchar();while(ch>‘9‘||ch<‘0‘) {if(ch==‘-‘) f=-1;ch=getchar();}while(ch>=‘0‘&&ch<=‘9‘) { x=x*10+ch-‘0‘;ch=getchar();}return x*f;}
31
32 struct Point{
33     LL x,y;
34     Point(){}
35     Point(LL _x,LL _y):x(_x),y(_y){}
36     Point operator + (const Point &t)const{
37         return Point(x+t.x,y+t.y);
38     }
39     Point operator - (const Point &t)const{
40         return Point(x-t.x,y-t.y);
41     }
42     LL operator * (const Point &t)const{
43         return x*t.y-y*t.x;
44     }
45     LL operator ^ (const Point &t)const{
46         return x*t.x+y*t.y;
47     }
48     bool operator < (const Point &b)const{
49         if (y * 1LL * b.y <= 0) {
50         if (y > 0 || b.y > 0) return y < b.y;
51         if (y == 0 && b.y == 0) return x < b.x;
52         }
53         return (*this)*b > 0;
54     }
55 }p[N],v[N<<1];
56
57 int main(){
58     int n;
59     while(~scanf("%d",&n)){
60         for(int i=0;i<n;i++) scanf("%I64d%I64d",&p[i].x,&p[i].y);
61         LL ans=1LL*n*(n-1)*(n-2)/6,tem=0;
62         for(int k=0;k<n;k++){
63             int cnt=0;
64             for(int i=0;i<n;i++){
65                 if(k==i)continue;
66                 v[cnt++]=p[i]-p[k];
67             }
68             sort(v,v+cnt);
69             for(int i=0;i<cnt;i++) v[i+cnt]=v[i];
70             int cxt=0;
71             for(int i=1;i<cnt;i++){
72                 if(v[i-1]*v[i]==0&&(v[i-1]^v[i])>0) cxt++;
73                 else cxt=0;
74                 tem+=cxt;
75             }
76             for(int i=0,p1=0,p2=0;i<cnt;i++){
77                 while(p1<=i||(p1<i+cnt&&v[p1]*v[i]<0&&(v[p1]^v[i])>0)) p1++;
78                 while(p2<=i||(p2<i+cnt&&v[p2]*v[i]<0)) p2++;
79                 ans-=p2-p1;
80             }
81         }
82         printf("%I64d\n",ans-tem/2);
83     }
84     return 0;
85 }
时间: 2024-08-02 02:38:18

多校2016 1004 HDU5784 统计锐角三角形数目的相关文章

HDU 4864(多校)1004 Task

Problem Description Today the company has m tasks to complete. The ith task need xi minutes to complete. Meanwhile, this task has a difficulty level yi. The machine whose level below this task's level yi cannot complete this task. If the company comp

MapReduce流程、如何统计任务数目以及Partitioner

核心功能描述 应用程序通常会通过提供map和reduce来实现 Mapper和Reducer接口,它们组成作业的核心. Map是一类将输入记录集转换为中间格式记录集的独立任务. 这种转换的中间格式记录集不需要与输入记录集的类型一致.一个给定的输入键值对可以映射成0个或多个输出键值对.Hadoop Map/Reduce框架为每一个InputSplit产生一个map任务,而每个InputSplit是由该作业的InputFormat产生的. 什么是InputSplit?InputSplit是指分片,在

统计文件数目(不包括隐藏文件/文件夹)

统计文件数目(不包括隐藏文件/文件夹) ls -l | grep "^-" | wc -l 统计当前目录下文件的数目 ls -lR | grep "^-" | wc -l 统计当前目录下文件的数目,包括子目录里的 ls -l | grep "^d" | wc -l 统计当前目录下文件夹(也就是目录)的数目 ls -lR | grep "^d" | wc -l 统计当前目录下文件夹(也就是目录)的数目,包括子目录里的 注意是英文

统计碱基数目、GC含量、read数、最长的read、最短的read及平均read长度

# 用于fasta格式文件的碱基数目和GC含量的统计 grep -v '>' input.fa| perl -ne  '{$count_A=$count_A+($_=~tr/A//);$count_T=$count_T+($_=~tr/T//);$count_G=$count_G+($_=~tr/G//);$count_C=$count_C+($_=~tr/C//);$count_N=$count_N+($_=~tr/N//)};END{print qq{total count is },$co

C语言实现二叉树-利用二叉树统计单词数目

昨天刚参加了腾讯2015年在线模拟考: 四道大题的第一题就是单词统计程序的设计思想: 为了记住这一天,我打算今天通过代码实现一下: 我将用到的核心数据结构是二叉树: (要是想了解简单二叉树的实现,可以参考我的另一篇文章:http://www.cnblogs.com/landpack/p/4783120.html) Problem 我需要统计的单词是在程序直接硬编码的: 这样做得原因是省略了文件输入输出所带来的困惑: 我的每篇文章,一般只说一个主题: 这样也方便我日后复习: Solution 首先

多校3 1004 Painter

Painter Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 497    Accepted Submission(s): 239 Problem Description Mr. Hdu is an painter, as we all know, painters need ideas to innovate , one day, h

hdu多校(二) 1004 1007 1010

Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 0    Accepted Submission(s): 0 Problem Description Alice and Bob are playing a game.The game is played on a set of positive integers from 1 t

OpenCV统计米粒数目-计算联通区域的个数及联通区域内像素的个数

分享一下我老师大神的人工智能教程吧.零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!http://www.captainbed.net 基于对话框的程序. 实现界面: 打开图片的消息响应函数: void CcountRiceDlg::OnBnClickedOpen() { // TODO: 在此添加控件通知处理程序代码 TCHAR szFilters[]=_T("BMP Files (*.bmp)|*.png|All Files (*.*)|*.*||")

统计JAR包DEX文件中的方法数目

 前段时间做Android项目中,一直出现方法数超过65535的问题,如果混淆后代码中的方法数目没有超过65535,可以通过 在project.properties文件中加上一行dex.force.jumbo=true,解决这个问题. 后来自己参考了网上的一些方法,写了个小工具用来统计JAR包和DEX文件中的方法数目.主要原理就是利用DEX的文件结构的文件头中有个method_ids_siz来统计方法数目. 现在分享出来,代码如下,直接拷贝编译成JAR包,然后控制台:java -jar XXX.