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点共线的组合数的更多相关文章

  1. hdu 5020 求三点共线的组合数(容器记录斜率出现次数)

    题意:       给你n个点,问你3点共线的组合数有多少,就是有多少种组合是满足3点共线的. 思路:      一开始抱着试1试的态度,暴力了一个O(n^3),结果一如既往的超时了,然后又在刚刚超时 ...

  2. 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),求函 ...

  3. hdu 2857 求点关于线段的对称点

    本来很简单的一个题,但是有个大坑: 因为模板中Tline用到了直线的一般方程ax+by+c=0,所以有种很坑的情况需要特判: 斜率不存在啊喂 老子坑了一下午2333 #include <math ...

  4. HDU 2196 求树上所有点能到达的最远距离

    其实我不是想做这道题的...只是今天考试考了一道类似的题...然后我挂了... 但是乱搞一下还是有80分....可惜没想到正解啊! 所以今天的考试题是: 巡访 (path.pas/c/cpp) Cha ...

  5. HDU 2009 求数列的和

    题目链接:HDU 2009 Description 数列的定义如下: 数列的第一项为n,以后各项为前一项的平方根,求数列的前m项的和. Input 输入数据有多组,每组占一行,由两个整数n(n< ...

  6. HDU 2006 求奇数的乘积

    http://acm.hdu.edu.cn/showproblem.php?pid=2006 Problem Description 给你n个整数,求他们中所有奇数的乘积.   Input 输入数据包 ...

  7. HDU 2003 求绝对值

    http://acm.hdu.edu.cn/showproblem.php?pid=2003 Problem Description 求实数的绝对值.   Input 输入数据有多组,每组占一行,每行 ...

  8. HDU 2023 求平均成绩

    Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status Practice HDU ...

  9. poj 3463/hdu 1688 求次短路和最短路个数

    http://poj.org/problem?id=3463 http://acm.hdu.edu.cn/showproblem.php?pid=1688 求出最短路的条数比最短路大1的次短路的条数和 ...

随机推荐

  1. PHP与apache配置

    在apache 的安装路径中找到 \conf\httpd.conf文件 在 LoadModule最后面添加如下代码: PHPIniDir "D:\PHP"LoadModule ph ...

  2. WinForm多线程编程与Control.Invoke的应用浅谈

    在WinForm开发中,我们通常不希望当窗体上点了某个按钮执行某个业务的时候,窗体就被卡死了,直到该业务执行完毕后才缓过来.一个最直接的方法便是使用多线程.多线程编程的方式在WinForm开发中必不可 ...

  3. Hive—学习笔记(一)

    主要内容: 1.Hive的基本工能机制和概念 2.hive的安装和基本使用 3.HQL 4.hive的脚本化运行使用方式 5.hive的基本语法--建表语法 6.hive的基本语法--内部表和外部表. ...

  4. sysbench——服务器cpu性能测试

    一.前言 最近在工作中需要测试cpu占用率.内存占用率,我想要寻找一种合适的能提高cpu占用率的工具及方法.先尝试了使用 echo "scale=5000; 4*a(1)" | b ...

  5. oracle,PL/SQL新建表

    创建用户 -- Create the user create user U_HQ_JAVA default tablespace USERS temporary tablespace TEMP pro ...

  6. 72. Edit Distance (String; DP)

    Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2 ...

  7. Petya and Array (权值线段树+逆序对)

    Petya and Array http://codeforces.com/problemset/problem/1042/D time limit per test 2 seconds memory ...

  8. 快速排序C++实现

    #include<iostream> using namespace std;class quicksort{ public: int quicks(int *a,int low,int ...

  9. swift - 代码创建 pickerView 显示或隐藏横线

    import UIKit class VC1: UIViewController { fileprivate lazy var pickerV : UIPickerView = { let v = U ...

  10. WebAPI 抛出HttpResponseException异常

    [HttpGet] public List<UserInfo> GetList() { try { List<UserInfo> list = new List<User ...