hdu 5020 求3点共线的组合数
http://acm.hdu.edu.cn/showproblem.php?pid=5020
求3点共线的组合数
极角排序然后组合数相加
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <queue>
#include <vector>
#include<map>
#include <iostream>
#include <algorithm>
using namespace std;
#define RD(x) scanf("%d",&x)
#define RD2(x,y) scanf("%d%d",&x,&y)
#define clr0(x) memset(x,0,sizeof(x))
typedef long long LL;
typedef pair<int,int> pii;
const double INF=2100000000; struct point
{
int x,y;
}p[1010];
int cmp(point a,point b)
{
return (a.x == b.x && a.y < b.y) || a.x < b.x;
}
int gcd(int a,int b)
{
return b == 0? a:gcd(b,a%b);
}
map <pii,int> hash;
int main()
{
int _,n;
RD(_);
while(_--){
RD(n);
for(int i = 0;i < n;++i)
RD2(p[i].x,p[i].y);
sort(p,p+n,cmp); map<pii,int>::iterator it;
int ans = 0;
for(int i = 0;i < n - 1;++i){
hash.clear();
for(int j = i+1;j < n;++j){
int dx = p[j].x - p[i].x,dy = p[j].y - p[i].y;
int g = gcd(dx,dy);
dx /= g,dy /= g;
hash[make_pair(dx,dy)]++;
}
for(it = hash.begin();it != hash.end();++it){
int x = it->second;
ans += x*(x - 1)/2;
}
}
cout<<ans<<endl;
}
return 0 ;
}
hdu 5020 求3点共线的组合数的更多相关文章
- hdu 5020 求三点共线的组合数(容器记录斜率出现次数)
题意: 给你n个点,问你3点共线的组合数有多少,就是有多少种组合是满足3点共线的. 思路: 一开始抱着试1试的态度,暴力了一个O(n^3),结果一如既往的超时了,然后又在刚刚超时 ...
- hdu 5105 求函数极值 函数求导/三分法
http://acm.hdu.edu.cn/showproblem.php?pid=5105 给定a,b,c,d,l,r,表示有一个函数f(x)=|a∗x3+b∗x2+c∗x+d|(L≤x≤R),求函 ...
- hdu 2857 求点关于线段的对称点
本来很简单的一个题,但是有个大坑: 因为模板中Tline用到了直线的一般方程ax+by+c=0,所以有种很坑的情况需要特判: 斜率不存在啊喂 老子坑了一下午2333 #include <math ...
- HDU 2196 求树上所有点能到达的最远距离
其实我不是想做这道题的...只是今天考试考了一道类似的题...然后我挂了... 但是乱搞一下还是有80分....可惜没想到正解啊! 所以今天的考试题是: 巡访 (path.pas/c/cpp) Cha ...
- HDU 2009 求数列的和
题目链接:HDU 2009 Description 数列的定义如下: 数列的第一项为n,以后各项为前一项的平方根,求数列的前m项的和. Input 输入数据有多组,每组占一行,由两个整数n(n< ...
- HDU 2006 求奇数的乘积
http://acm.hdu.edu.cn/showproblem.php?pid=2006 Problem Description 给你n个整数,求他们中所有奇数的乘积. Input 输入数据包 ...
- HDU 2003 求绝对值
http://acm.hdu.edu.cn/showproblem.php?pid=2003 Problem Description 求实数的绝对值. Input 输入数据有多组,每组占一行,每行 ...
- HDU 2023 求平均成绩
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status Practice HDU ...
- poj 3463/hdu 1688 求次短路和最短路个数
http://poj.org/problem?id=3463 http://acm.hdu.edu.cn/showproblem.php?pid=1688 求出最短路的条数比最短路大1的次短路的条数和 ...
随机推荐
- time和datetime
一.time模块常用函数1. time()函数time()函数返回的是时间戳(timestamp).所谓时间戳指的是从1970年1月1日00:00:00开始按秒计算的偏移量.其他返回时间戳方式的函数还 ...
- string类小结
要想使用标准C++中string类,必须要包含 #include <string>// 注意是<string>,不是<string.h>,带.h的是C语言中的头文件 ...
- [leetcode]721. Accounts Merge账户合并
Given a list accounts, each element accounts[i] is a list of strings, where the first element accoun ...
- jquery源码学习-构造函数(2)
最近几天一直在研究jquery源码,由于水平太低看得昏头转向.本来理解的也不是很深刻,下面就用自己的想法来说下jquery是如何定义构造函数初始化的.如果有什么不对的地方,希望个位高手指出. 一般写 ...
- Spring框架的事务管理之基于AspectJ的XML方式(重点掌握)
1. 步骤一:恢复转账开发环境(转账开发环境见“https://www.cnblogs.com/wyhluckdog/p/10137283.html”) 2.步骤二:引入AOP的开发包3.步骤三:引入 ...
- 【转】从源码浅析MVC的MvcRouteHandler、MvcHandler和MvcHttpHandler
原文:http://www.cnblogs.com/jeffwongishandsome/archive/2012/01/08/2316521.html 熟悉WebForm开发的朋友一定都知道,Pag ...
- linux 动态库 静态库 函数覆盖
本文讨论了linux动态库 静态库中函数的覆盖问题. 测试目的: 同名函数,分别打成动态库libdync_lib.so与静态库libstatic_lib.a,并把libstatic_lib.a打到另 ...
- Storm 系列(二)实时平台介绍
Storm 系列(二)实时平台介绍 本章中的实时平台是指针对大数据进行实时分析的一整套系统,包括数据的收集.处理.存储等.一般而言,大数据有 4 个特点: Volumn(大量). Velocity(高 ...
- Zookeeper 系列(五)Curator API
Zookeeper 系列(五)Curator API 一.Curator 使用 Curator 框架中使用链式编程风格,易读性更强,使用工程方法创建连接对象使用. (1) CuratorFramewo ...
- mvc 验证封装到某个特征类里[特性的使用]