hdu5785(极角排序求所有锐角钝角个数)
做法很显然,求出所有的锐角和钝角就能求出有多少个锐角三角形了。
我用了愚钝的方法,写了两三个小时。。。
看了下别人简单的代码。学习了下做法。
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(极角排序求所有锐角钝角个数)的更多相关文章
- L3-021 神坛(极角排序求三角形最小面积)
在古老的迈瑞城,巍然屹立着 n 块神石.长老们商议,选取 3 块神石围成一个神坛.因为神坛的能量强度与它的面积成反比,因此神坛的面积越小越好.特殊地,如果有两块神石坐标相同,或者三块神石共线,神坛的面 ...
- poj 1696 极角排序求最长逆时针螺旋线
Space Ant Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4970 Accepted: 3100 Descrip ...
- Wall--POJ1113(极角排序+求凸包)
http://poj.org/problem?id=1113 题目大意:现在要给n个点,让你修一个围墙把这些点围起来,距离最小是l 分析 :现在就是求凸包的周长然后再加上一个圆的周长 #includ ...
- POJ 2388 Who's in the Middle(水~奇数个数排序求中位数)
题目链接:http://poj.org/problem?id=2388 题目大意: 奇数个数排序求中位数 解题思路:看代码吧! AC Code: #include<stdio.h> #in ...
- How Many Triangles (极角排序 + 尺取法)
题意:二维平面与有很多个点,然后求构成锐角三角形的个数. 思路:对于每一个三角形我们知道存在至少2个锐角,只要有一个钝角就不行了,所以我们的想法就是枚举所有夹角的状态,然后得知情况,确定用总个数减去- ...
- hdu-5784 How Many Triangles(计算几何+极角排序)
题目链接: How Many Triangles Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Jav ...
- UVaLive 4064 Magnetic Train Tracks (极角排序)
题意:给定 n 个不三点共线的点,然后问你能组成多少锐角或者直角三角形. 析:可以反过来求,求有多少个钝角三角形,然后再用总的减去,直接求肯定会超时,但是可以枚举每个点,以该点为钝角的那个顶点,然后再 ...
- 【极角排序、扫描线】UVa 1606 - Amphiphilic Carbon Molecules(两亲性分子)
Shanghai Hypercomputers, the world's largest computer chip manufacturer, has invented a new class of ...
- POJ 2280 Amphiphilic Carbon Molecules 极角排序 + 扫描线
从TLE的暴力枚举 到 13313MS的扫描线 再到 1297MS的简化后的扫描线,简直感觉要爽翻啦.然后满怀欣喜的去HDU交了一下,直接又回到了TLE.....泪流满面 虽说HDU的时限是2000 ...
随机推荐
- 批量解密SQLSERVER数据库中的各种对象的工具dbForge SQL Decryptor2.1.11
参考地址: http://www.cnblogs.com/lyhabc/p/3505677.html SQLPROMPT5.3对各种加密对象的解密测试 SQL2005解密已经被加密的存储过程 昨天ah ...
- C#读取Excel显示到repeater中
首先需要一个用来存储我们需要显示的内容,防止页面回发丢失(添加时使用) #region 缓存文件 private DataTable excelData; /// <summary> // ...
- 2013 Asia Regional Changchun I 题,HDU(4821),Hash
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=4821 解题报告:搞了很久,总算搞出来了,还是参考了一下网上的解法,的确很巧,和上次湘潭的比 ...
- 2016年11月30日 星期三 --出埃及记 Exodus 20:21
2016年11月30日 星期三 --出埃及记 Exodus 20:21 The people remained at a distance, while Moses approached the th ...
- 注册页面的验证 WEB的三级联动
1.js中window.onload = function () {};表示当页面都加载完了之后才走里面的内容. 2.当函数中遇到return时,会跳出函数,return后面的内容不再继续进行,就是后 ...
- 【Thread】多线程的异常处理?
线程中处理异常是个头疼的问题,在异步的代码中,如何将异常捕获. 捕获异常后,将异常反馈给开发者,或用户.一般来说,反馈给开发者,多数方式在是日志中打印异常日志:而反馈给用户,多数是在界面上友好提示(比 ...
- 微软的决心,开发者的信心!惊喜的 Connect(); // 2016
微软的决心,开发者的信心!惊喜的 Connect(); // 2016 Visual Studio for Mac 2014 年 11 月 13 日,微软宣布 .NET 开源与跨平台.两年后的今天 ...
- Web文件的ContentType类型收集
".*"="application/octet-stream"".001"="application/x-001"&qu ...
- 【leetcode❤python】231. Power of Two
#-*- coding: UTF-8 -*- class Solution(object): def isPowerOfTwo(self, n): if(n<=0): ...
- Socket重叠IO
1.为什么到现在才弄懂这个 不知道这个Socket重叠IO这种模型是不是socket IO完成端口的基础,不过我感觉,学习一下这个再去学习socket IO完成端口是比较有好处的. 这个Scoket重 ...