http://codeforces.com/contest/872/problem/E

E. Points, Lines and Ready-made Titles
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given n distinct points on a plane with integral coordinates. For each point you can either draw a vertical line through it, draw a horizontal line through it, or do nothing.

You consider several coinciding straight lines as a single one. How many distinct pictures you can get? Print the answer modulo 109 + 7.

Input

The first line contains single integer n (1 ≤ n ≤ 105) — the number of points.

n lines follow. The (i + 1)-th of these lines contains two integers xiyi ( - 109 ≤ xi, yi ≤ 109) — coordinates of the i-th point.

It is guaranteed that all points are distinct.

Output

Print the number of possible distinct pictures modulo 109 + 7.

Examples
input
4
1 1
1 2
2 1
2 2
output
16
input
2
-1 -1
0 1
output
9
Note

In the first example there are two vertical and two horizontal lines passing through the points. You can get pictures with any subset of these lines. For example, you can get the picture containing all four lines in two ways (each segment represents a line containing it).

The first way:The second way:

In the second example you can work with two points independently. The number of pictures is 32 = 9.

题意:

给出二维平面上的n个点,每个点可以画一条水平线,也可以画一条竖直线,也可以什么都不画

求 图案 方案数

思路:把冲突的点放到一个连通块中,对每个连通块单独处理,乘法原理计数

对于一个连通块来说,n个点最多有n+1条边

最开始一个点有2条边,然后每加入一条边,都要加入一个点

当然,可以只加点不加边(例:井字形)

所以 边数E<=点数P+1

因为连通块里加入的这些边,保证不冲突

所以

1、E==P+1

因为一个点只能连一条边,所以这个连通块最多只能有P条边

所以这个连通块的方案数=C(E,1)+C(E,2)+……+ C(E,P)= 2^E-1

2、E<=P

方案数=C(E,1)+C(E,2)+……+C(E,E)= 2^E

#include<cstdio>
#include<iostream>
#include<algorithm> #define N 100001 using namespace std; const int mod=1e9+; int hasx[N],hasy[N],x[N],y[N]; int fa[N*]; int sizp[N],size[N*]; void read(int &x)
{
x=; int f=; char c=getchar();
while(!isdigit(c)) { if(c=='-') f=-; c=getchar(); }
while(isdigit(c)) { x=x*+c-''; c=getchar(); }
x*=f;
} int find(int i) { return fa[i]==i ? i : fa[i]=find(fa[i]); } int Pow(int a,int b)
{
int res=;
for(;b;a=1ll*a*a%mod,b>>=)
if(b&) res=1ll*res*a%mod;
return res;
} int main()
{
int n; read(n);
for(int i=;i<=n;i++) read(x[i]),read(y[i]),hasx[i]=x[i],hasy[i]=y[i];
sort(hasx+,hasx+n+); sort(hasy+,hasy+n+);
int tot1=unique(hasx+,hasx+n+)-hasx-,cnt=tot1;
for(int i=;i<=n;i++) x[i]=lower_bound(hasx+,hasx+tot1+,x[i])-hasx;
int tot2=unique(hasy+,hasy+n+)-hasy-; cnt+=tot2;
for(int i=;i<=n;i++) y[i]=lower_bound(hasy+,hasy+tot2+,y[i])-hasy;
for(int i=;i<=cnt;i++) fa[i]=i;
for(int i=;i<=n;i++) fa[find(x[i])]=find(y[i]+tot1);
for(int i=;i<=n;i++) sizp[find(x[i])]++;
for(int i=;i<=cnt;i++) size[find(i)]++;
int ans=;
for(int i=;i<=cnt;i++)
if(find(i)==i)
{
if(sizp[i]+==size[i]) ans=1ll*ans*(Pow(,size[i])+mod-)%mod;
else ans=1ll*ans*Pow(,size[i])%mod;
}
printf("%d",ans);
}

codeforces 872E. Points, Lines and Ready-made Titles的更多相关文章

  1. Codeforces 871C 872E Points, Lines and Ready-made Titles

    题 OvO http://codeforces.com/contest/871/problem/C ( Codeforces Round #440 (Div. 1, based on Technocu ...

  2. Codeforces 870E Points, Lines and Ready-made Titles:并查集【两个属性二选一】

    题目链接:http://codeforces.com/problemset/problem/870/E 题意: 给出平面坐标系上的n个点. 对于每个点,你可以画一条经过这个点的横线或竖线或什么都不画. ...

  3. Codeforces 870E Points, Lines and Ready-made Titles 计数

    题目链接 题意 给定二维坐标上的\(n\)个点,过每个点可以 画一条水平线 或 画一条竖直线 或 什么都不画,并且若干条重合的直线被看做同一条.问共可能得到多少幅不同的画面? 题解 官方题解 仆の瞎扯 ...

  4. Codeforces Round #440 (Div. 1, based on Technocup 2018 Elimination Round 2) C - Points, Lines and Ready-made Titles

    C - Points, Lines and Ready-made Titles 把行列看成是图上的点, 一个点(x, y)就相当于x行 向 y列建立一条边, 我们能得出如果一个联通块是一棵树方案数是2 ...

  5. 【题解】Points, Lines and Ready-made Titles Codeforces 871C 图论

    Prelude 真是一道好题,然而比赛的时候花了太多时间在B题上,没时间想这个了QAQ. 题目链接:萌萌哒传送门(.^▽^) Solution 观察样例和样例解释,我们发现,假如有四个点,恰好占据在某 ...

  6. CodeForces 19D Points

    Pete and Bob invented a new interesting game. Bob takes a sheet of paper and locates a Cartesian coo ...

  7. R语言:多个因变量时,如何在plot函数中画多条曲线(plot,points,lines,legend函数)

    最近阅读一篇文献<Regional and individual variations in the function of the human eccrine sweat gland>, ...

  8. CodeForces 19D Points (线段树+set)

    D. Points time limit per test 2 seconds memory limit per test 256 megabytes input standard input out ...

  9. 『ACM C++』 Codeforces | 1066A - Points in Segments

    大一生活真 特么 ”丰富多彩“ ,多彩到我要忙到哭泣,身为班长,很多班级的事情需要管理,也是,什么东西都得体验学一学,从学生会主席.团委团总支.社团社长都体验过一番了,现在差个班长也没试过,就来体验了 ...

随机推荐

  1. Yogurt factory

    Description The cows have purchased a yogurt factory that makes world-famous Yucky Yogurt. Over the ...

  2. Android源码项目目录结构

    src: 存放java代码 gen: 存放自动生成文件的. R.java 存放res文件夹下对应资源的id project.properties: 指定当前工程采用的开发工具包的版本 libs: 当前 ...

  3. CSS3:不可思议的border属性

    在CSS中,其border属性有很多的规则.对于一些事物,例如三角形或者其它的图像,我们仍然使用图片代替.但是现在就不需要了,我们可以用CSS形成一些基本图形,我分享了一些关于这方面的技巧. 1.正三 ...

  4. eclipse建包的一些细节

    com.a :com.b 等会先在com文件夹下在 建立 a,b两个子文件夹,引用路径时 不可"*\\com.a\\*"而是"*\\com\\a\\*"这点基础 ...

  5. <<世界是数字的>>读书笔记

    <世界是数字的>这本书是大学职业规划老师介绍个我读的,从着本中我学到了很多. 第一章,计算机里有什么.这个问题可以从两方面来看:逻辑上或者说功能上的组成,即每一部分是什么.做什么.怎样做. ...

  6. 处理了一个以前写的java小程序的异常

    之前用java做过0-99的数字和英文之间的翻译,输入数字就会翻译成英文,输入英文会翻译成数字,比如输入56  输出fiftysix   输入fiftysix  输出56, 发现这会有一个异常,当输入 ...

  7. C++ Primer Plus学习:第四章

    C++入门第四章:复合类型 1 数组 数组(array)是一种数据格式,能够存储多个同类型的值. 使用数组前,首先要声明.声明包括三个方面: 存储每个元素中值的类型 数组名 数组中的元素个数 声明的通 ...

  8. Linux系统中增加swap空间大小

    在我的树莓派pi3上编译dlib库时,发现由于内存不足导致编译失败.树莓派是1G内存,swap只有50M,因此将swap增加到500M,编译通过.具体设置方法如下: 使用free命令带上m参数,查看s ...

  9. 倒计时60s 代码

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  10. Qt程序打包,自动拷贝依赖文件

    版权声明:若无来源注明,Techie亮博客文章均为原创. 转载请以链接形式标明本文标题和地址: 本文标题:Qt程序打包,自动拷贝依赖文件     本文地址:http://techieliang.com ...