题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5738

题意:从n(n <= 1000)个点(有重点)中选出m(m > 1)个点(选出的点只看标号,不看具体坐标)合成一个集合,问集合中的点共线(可以重合)的集合个数?

思路:按照x,y双关键字排序,之后对每一个点求出所有以它为一个端点的线段个数;

及时计数:要求以当前点为端点的线段数,分成两种情况:

1. 线段就为当前点,即将当前点的重点合成一个点,C(n,2)+C(n,3)+...+C(n,n) = 2n-n-1;

2. 除了包含若干个当前点还有其他点,构成线段;这时对于当前点可取值为2n-1;这时因为其它点是否有重点,对于当前点并没有什么区别;

直接同一斜率的点的个数相加即可(点的个数是指重点缩为一点)细节:不要使用unique来编码。。直接O(n)在线编码好得多;否则还需重载 ==运算符,而目的只是求解出当前节点的重点个数;

对于斜率最好使用最简分数的形式保存在map中;

 #pragma comment(linker, "/STACK:1024000000,1024000000")
#include<bits/stdc++.h>
using namespace std;
#define rep0(i,l,r) for(int i = (l);i < (r);i++)
#define rep1(i,l,r) for(int i = (l);i <= (r);i++)
#define rep_0(i,r,l) for(int i = (r);i > (l);i--)
#define rep_1(i,r,l) for(int i = (r);i >= (l);i--)
#define MS0(a) memset(a,0,sizeof(a))
#define MS1(a) memset(a,-1,sizeof(a))
#define MSi(a) memset(a,0x3f,sizeof(a))
#define inf 0x3f3f3f3f
#define lson l, m, rt << 1
#define rson m+1, r, rt << 1|1
#define A first
#define B second
#define MK make_pair
#define esp 1e-8
#define mod 1000000007
#define zero(x) (((x)>0?(x):-(x))<eps)
#define bitnum(a) __builtin_popcount(a)
#define clear0 (0xFFFFFFFE) typedef pair<int,int> PII;
typedef long long ll;
typedef unsigned long long ull;
template<typename T>
void read1(T &m)
{
T x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
m = x*f;
}
template<typename T>
void read2(T &a,T &b){read1(a);read1(b);}
template<typename T>
void read3(T &a,T &b,T &c){read1(a);read1(b);read1(c);}
template<typename T>
void out(T a)
{
if(a>) out(a/);
putchar(a%+'');
}
inline ll gcd(ll a,ll b){ return b == ? a: gcd(b,a%b); }
struct point2{
ll x, y;
}p[];
bool cmp(point2 a,point2 b)
{
return a.x == b.x ? a.y < b.y: a.x < b.x;
}
map<PII,int> mp;
ll _2[];
int main()
{
//freopen("data.txt","r",stdin);
//freopen("out.txt","w",stdout);
_2[] = ;
rep1(i,,) _2[i] = (_2[i-]<<)%mod;
int T, n;
cin >> T;
while(T--){
ll ans = ;
read1(n);
rep0(i,,n) read2(p[i].x, p[i].y);
sort(p,p+n,cmp);
rep0(i,,n){
int cnt = ;
while(p[i+].x == p[i].x && p[i+].y == p[i].y) cnt++,i++;
mp.clear();
rep0(j,i+,n){
ll dy = p[i].y - p[j].y,
dx = p[i].x - p[j].x;
ll g = gcd(dy,dx);
mp[MK(dy/g, dx/g)]++;
}
ans = (ans + _2[cnt]-cnt-)% mod;
for(auto v = mp.begin(); v != mp.end(); v++){
ans = (ans + (_2[cnt]-)*(_2[v->second]-))% mod;
}
}
printf("%lld\n", ans);
}
return ;
}

hdu 5738 2016 Multi-University Training Contest 2 Eureka 计数问题(组合数学+STL)的更多相关文章

  1. 2016 Al-Baath University Training Camp Contest-1

    2016 Al-Baath University Training Camp Contest-1 A题:http://codeforces.com/gym/101028/problem/A 题意:比赛 ...

  2. hdu 4915 Parenthese sequence--2014 Multi-University Training Contest 5

    主题链接:http://acm.hdu.edu.cn/showproblem.php?pid=4915 Parenthese sequence Time Limit: 2000/1000 MS (Ja ...

  3. hdu 4902 Nice boat--2014 Multi-University Training Contest 4

    题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=4902 Nice boat Time Limit: 30000/15000 MS (Java/Othe ...

  4. hdu 4925 Apple Tree--2014 Multi-University Training Contest 6

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4925 Apple Tree Time Limit: 2000/1000 MS (Java/Others ...

  5. HDU校赛 | 2019 Multi-University Training Contest 6

    2019 Multi-University Training Contest 6 http://acm.hdu.edu.cn/contests/contest_show.php?cid=853 100 ...

  6. HDU校赛 | 2019 Multi-University Training Contest 5

    2019 Multi-University Training Contest 5 http://acm.hdu.edu.cn/contests/contest_show.php?cid=852 100 ...

  7. HDU校赛 | 2019 Multi-University Training Contest 4

    2019 Multi-University Training Contest 4 http://acm.hdu.edu.cn/contests/contest_show.php?cid=851 100 ...

  8. HDU校赛 | 2019 Multi-University Training Contest 3

    2019 Multi-University Training Contest 3 http://acm.hdu.edu.cn/contests/contest_show.php?cid=850 100 ...

  9. HDU校赛 | 2019 Multi-University Training Contest 2

    2019 Multi-University Training Contest 2 http://acm.hdu.edu.cn/contests/contest_show.php?cid=849 100 ...

随机推荐

  1. emoji表情符处理替换成空格

    /**    * 用filterOffUtf8Mb4    * Description: 过滤率四个字节的utf-8字符(emoji表情符),替换成四个空格.    *         四字节utf- ...

  2. linux之磁盘配额(quota)

    1.什么是quota 简单的说就是限制用户对磁盘空间的使用量. 因为Linux是多用户多任务的操作系统,许多人共用磁盘空间,为了合理的分配磁盘空间,于是就有了quota的出现. 2.quota的用途  ...

  3. MyEclipse设置编码方式 转载【http://www.cnblogs.com/susuyu/archive/2012/06/27/2566062.html】

    1.windows->Preferences……打开"首选项"对话框,左侧导航树,导航到general->Workspace, 右侧Text file encoding ...

  4. 利用css使文本在限制几行之后隐藏

    想要在布局中显示一段新闻的标题或是内容,特别是内容,东西超多...下面的方法就是通过css来控制文本显示多少的: 首先在html中写上: <p class="ellipsis" ...

  5. Kinect For Windows V2开发日志一:开发环境的配置

    算是正式进军Kinect了,前段时间学的东西现在就忘了,于是从此开始记录一下. 目前为止大部分的学习资料来自于Heresy的博客,写的非常优秀,清晰明了,十分感谢.开发语言为C++,应该会一直使用,但 ...

  6. codeforces 677D D. Vanya and Treasure(二维线段树)

    题目链接: D. Vanya and Treasure time limit per test 1.5 seconds memory limit per test 256 megabytes inpu ...

  7. ZOV压敏电阻

    http://www.zov.net.cn/download/spd_07D.htm http://item.taobao.com/item.htm?spm=a1z10.5.w4002-1369342 ...

  8. BZOJ 3713

    Description 斐波那契数列的定义为:k=0或1时,F[k]=k:k>1时,F[k]=F[k-1]+F[k-2].数列的开头几项为0,1,1,2,3,5,8,13,21,34,55,…你 ...

  9. Python类和实例

    面向对象最重要的概念就是类(Class)和实例(Instance),必须牢记类是抽象的模板,比如Student类,而实例是根据类创建出来的一个个具体的“对象”,每个对象都拥有相同的方法,但各自的数据可 ...

  10. asp.net中导出excel数据的方法汇总

    1.由dataset生成 代码如下 复制代码 public void CreateExcel(DataSet ds,string typeid,string FileName)    {    Htt ...