做法很显然,求出所有的锐角和钝角就能求出有多少个锐角三角形了。

我用了愚钝的方法,写了两三个小时。。。

看了下别人简单的代码。学习了下做法。

sort(temp+,temp+cnt+);//排序
For(j,,cnt)//这一步,复制了一遍所有角,然后就能很好的处理在逆时针的情况
{
temp[j+cnt]=temp[j]+*PI;
}
int l=,r=,le=;
For(j,,cnt)
{
while(temp[r]-temp[j]<PI&&r<=*cnt)r++;//找出<180的角
while(temp[l]-temp[j]<0.5*PI&&l<=*cnt)l++;//找出<90度的角
while(temp[le]-temp[j]<=eps&&le<=*cnt)le++;//排除一条直线的情况
ans1=ans1+r-l;
ans2=ans2+l-le;
}

再附上自己拙略的代码:

//
// main.cpp
// hdu5784
//
// Created by New_Life on 16/8/10.
// Copyright © 2016年 chenhuan001. All rights reserved.
// #include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
using namespace std;
#define PI acos(-1.0) struct point
{
int x,y;
double shita;
}g[],tg[]; int cmp(point p1,point p2)
{
return p1.shita<p2.shita;
} double operator*(point p1, point p2) // 计算叉乘 p1 × p2
{
return ((long long)p1.x * p2.y - (long long)p2.x * p1.y);
}
double operator&(point p1, point p2) { // 计算点积 p1·p2
return ((long long)p1.x * p2.x + (long long)p1.y * p2.y);
} int dsub(int p1,int p2)
{
return (tg[p1]*tg[p2]<=)&&( (tg[p1]&tg[p2])> );
} int savenum[]; int main(int argc, const char * argv[]) {
int n;
while(cin>>n)
{
for(int i=;i<n;i++)
{
scanf("%d%d",&g[i].x,&g[i].y);
}
long long ans = ;
for(int i=;i<n;i++)
{
int cnt = ;
for(int j=;j<n;j++)
{
if(j==i) continue;
int tx = g[j].x - g[i].x;
int ty = g[j].y - g[i].y;
tg[cnt].x = tx; tg[cnt].y = ty;
tg[cnt++].shita = atan2(ty, tx);
}
if(cnt < ) continue;
sort(tg,tg+cnt,cmp);
memset(savenum,,sizeof(savenum)); int scnt= cnt;
int tcnt = ;
savenum[tcnt++] = ;
for(int j=;j<cnt;j++)
{
if( tg[j]*tg[tcnt-]== && ( (tg[j]&tg[tcnt-])> ) )
{
savenum[tcnt-]++;
}
else
{
tg[tcnt] = tg[j];
savenum[tcnt] = ;
tcnt++;
}
} cnt = tcnt;
for(int j=;j<cnt;j++)
{
ans += savenum[j]*(savenum[j]-);
} if(cnt==) continue;
tcnt = ;
int lf=,rt=; while( dsub(,lf) ){
tcnt += savenum[lf];
lf = (lf-+cnt)%cnt;
if(lf == ) break;
}
lf = (lf+)%cnt;
while( rt!= && dsub(rt,) ) tcnt+=savenum[rt],rt = (rt+)%cnt;
//rt = (rt-1+cnt)%cnt;
ans += savenum[]*(tcnt-savenum[]);
ans -= *savenum[]*(scnt-tcnt); for(int j=;j<cnt;j++)
{
if(j == lf)
{
tcnt -= savenum[lf];
lf = (lf+)%cnt;
}
if(j == rt)
{
tcnt += savenum[j];
rt = (rt+)%cnt;
}
while( !dsub(j,lf) )
{
tcnt -= savenum[lf];
lf= (lf+)%cnt;
//if(lf == j) break;
}
while(rt!=j && dsub(rt,j) ) tcnt+=savenum[rt],rt=(rt+)%cnt;
ans += savenum[j]*(tcnt-savenum[j]);
ans -= *savenum[j]*(scnt-tcnt);
}
}
cout<<ans/<<endl;
}
return ;
}
/*
4
0 0
0 1
1 0
1 1
9
0 0
2 0
0 1
2 1
1 0
1 1
0 2
1 2
2 2
4
0 0
1 1
2 2
3 3
5
0 0
1 1
2 2
-1 0
10000 0
*/

hdu5785(极角排序求所有锐角钝角个数)的更多相关文章

  1. L3-021 神坛(极角排序求三角形最小面积)

    在古老的迈瑞城,巍然屹立着 n 块神石.长老们商议,选取 3 块神石围成一个神坛.因为神坛的能量强度与它的面积成反比,因此神坛的面积越小越好.特殊地,如果有两块神石坐标相同,或者三块神石共线,神坛的面 ...

  2. poj 1696 极角排序求最长逆时针螺旋线

    Space Ant Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4970   Accepted: 3100 Descrip ...

  3. Wall--POJ1113(极角排序+求凸包)

    http://poj.org/problem?id=1113 题目大意:现在要给n个点,让你修一个围墙把这些点围起来,距离最小是l 分析  :现在就是求凸包的周长然后再加上一个圆的周长 #includ ...

  4. POJ 2388 Who's in the Middle(水~奇数个数排序求中位数)

    题目链接:http://poj.org/problem?id=2388 题目大意: 奇数个数排序求中位数 解题思路:看代码吧! AC Code: #include<stdio.h> #in ...

  5. How Many Triangles (极角排序 + 尺取法)

    题意:二维平面与有很多个点,然后求构成锐角三角形的个数. 思路:对于每一个三角形我们知道存在至少2个锐角,只要有一个钝角就不行了,所以我们的想法就是枚举所有夹角的状态,然后得知情况,确定用总个数减去- ...

  6. hdu-5784 How Many Triangles(计算几何+极角排序)

    题目链接: How Many Triangles Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Jav ...

  7. UVaLive 4064 Magnetic Train Tracks (极角排序)

    题意:给定 n 个不三点共线的点,然后问你能组成多少锐角或者直角三角形. 析:可以反过来求,求有多少个钝角三角形,然后再用总的减去,直接求肯定会超时,但是可以枚举每个点,以该点为钝角的那个顶点,然后再 ...

  8. 【极角排序、扫描线】UVa 1606 - Amphiphilic Carbon Molecules(两亲性分子)

    Shanghai Hypercomputers, the world's largest computer chip manufacturer, has invented a new class of ...

  9. POJ 2280 Amphiphilic Carbon Molecules 极角排序 + 扫描线

    从TLE的暴力枚举 到 13313MS的扫描线  再到 1297MS的简化后的扫描线,简直感觉要爽翻啦.然后满怀欣喜的去HDU交了一下,直接又回到了TLE.....泪流满面 虽说HDU的时限是2000 ...

随机推荐

  1. Floyd-Warshall算法,简称Floyd算法

    Floyd-Warshall算法,简称Floyd算法,用于求解任意两点间的最短距离,时间复杂度为O(n^3). 使用条件&范围通常可以在任何图中使用,包括有向图.带负权边的图. Floyd-W ...

  2. nohup & rabbitmq & python

    用Python脚本执行rabbitmq的消费 nohup python consumer.py > out.log & 结果郁闷啊,怎么都查看不到输出! 终于找到了答案: 原来pytho ...

  3. hnu Dirichlet's Theorem

    /* 求ax+b x属于区间[L,R];范围内素数的个数. a*R+b<=10^12 ; R-L+1<=10^6 枚举,超时. 1.如果GCD(a,b)>1 那么a+b 2*a+b ...

  4. reactjs入门到实战(三)---- 组件详解

    owner  >>> 传递 props this >>>是默认指向组件本身 key>>>不能没有,在复用的情况下 组件:例子 <!-- 输入 ...

  5. linux系统中如何查看日志 (常用命令2)

    cat tail -f 日 志 文 件 说 明 /var/log/message 系统启动后的信息和错误日志,是Red Hat Linux中最常用的日志之一 /var/log/secure 与安全相关 ...

  6. ①创建项目testpackage ②在pack2.B中添加方法f ③在类A中添加如下三个成员变量:int型的私有变量i float型的变量f double型的公有变量d 在pack1.B的main方法中为对象a的成员变量f和d分别赋值为2和3 在pack2.C的main方法中为对象a的成员变量d赋值为3

    package pack1; public class A { private int i; float f; public double d; public float getF() { retur ...

  7. div模拟表格使用display

    <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...

  8. Windows平台安装Redmine2.5.x

    安装准备 下载RubyInstaller和Development Kit,也可以使用RailsFTW,轻松搞定windows下的安装. 下载MySql 下载mysql-connector-c-noin ...

  9. Word和Windows有严重的bug这样下去微软堪忧

    Word和Windows对微软的重要性就像C语言的指针. Windows中特别常用的搜索功能有严重的bug,常常搜不到Excel文件. Word中的排版功能有严重的bug,有图超过几十页就无法排版了, ...

  10. echo输出到stderr

    echo "Your error message here" >&2 This is a normal echo (which goes to stdout), ho ...