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的次短路的条数和 ...
随机推荐
- Java中static代码块,{}大括号代码块,构造方法代码块执行顺序!
注:下列代码中的注释都是JUnit4单元测试运行结果. 首先,没有父类的(父类是Object)的类A package Static.of; public class A { { System.out. ...
- 一个团队和他们的调查表-----("调查表与调查结果分析"心得体会)
注:这篇blog主要是描述六小灵童团队在从接到调查表任务到分析调查数据最后完成本次任务的过程,以及过程中的点滴和心德体会.---蔡何 1.制表历程 随着课程的推进,我们逐步进入了软件项目中比较重要的需 ...
- 关于插入date型数据
create table student (name varchar2(10) not null primary key , enrolldate date not null);//创建student ...
- 20-最大k乘积问题
/* 最大k乘积问题 题目内容: 设I是一个n位十进制整数.如果将I划分为k段,则可得到k个整数. ...
- php中的declare
<?php // 事件的回调函数 function func_tick() { echo "call...\r\n"; } // 注册事件的回调函数 register_tic ...
- C#控制台自定义背景颜色,字体颜色大全
效果: using System; using System.Collections.Generic; using System.Linq; using System.Text; using Syst ...
- Golang之redis
redis是个开源的高性能的key-value的内存数据库,可以把它当成远程的数据结构. 支持的value类型非常多,比如string.list(链表).set(集合). hash表等等 redis性 ...
- debuginfo介绍
一.简介 深入理解debuginfo http://blog.csdn.net/chinainvent/article/details/24129311?reload 关于DWARF http://w ...
- htons、htonl与字节序大小端
判断字节序大小端code #include <stdio.h> int main() { ) == ) printf("big endian\n"); else pri ...
- js replace 用法
/g 表示全部 global 在很多项目中,我们经常需要使用JS,在页面前面对前台的某些元素做做修改,js 的replace()方法就必不可少. 经常使用"ABCABCabc". ...