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. 多源最短路——Floyd算法

    Floyd算法 问题的提出:已知一个有向网(或者无向网),对每一对定点vi!=vj,要求求出vi与vj之间的最短路径和最短路径的长度. 解决该问题有以下两种方法: (1)轮流以每一个定点为源点,重复执 ...

  2. 每日Scrum--No.3

    Yesterday:帮着队友一起打开地图 Today:学习迪杰斯特拉算法,试着编写程序代码 Problem:语法逻辑出错,在执行的时候,有的时候出现死循环,有的时候屏幕出现null和乱码.语句的编写有 ...

  3. MOOK学习

    课程选择及其理由 课程:c++程序设计 教师:魏英 学校:西北工业大学 总共:48讲 选择理由:我其实之前找了好几个,但由于小白,思考了下(迷茫,感觉好像都不错),然后看了一下大家都选择了西北工业大学 ...

  4. Qt多线程-QThreadPool线程池与QRunnable

    版权声明:若无来源注明,Techie亮博客文章均为原创. 转载请以链接形式标明本文标题和地址: 本文标题:Qt多线程-QThreadPool线程池与QRunnable     本文地址:https:/ ...

  5. (八)Jmeter怎么通过后置处理器去做关联

     一.Jmeter关联的方式: Jmeter中关联可以在需要获取数据的请求上 右键-->后置处理器 选择需要的关联方式,如下图有很多种方法可以提取动态变化数据: 二.正则表达式提取器: 1.比如 ...

  6. PHP面向对象之抽象类,抽象方法

    抽象类,抽象方法 抽象类: 是一个不能实例化的类: 定义形式: abstract  class  类名{} 为什么需要抽象类: 它是为了技术管理而设计! 抽象方法: 是一个只有方法头,没有方法体的方法 ...

  7. 深入解析ThreadLocal类

    先了解一下ThreadLocal类提供的几个方法: public T get() { } public void set(T value) { } public void remove() { } p ...

  8. 【C++】深度探索C++对象模型读书笔记--执行期语意学(Runtime Semantics)

    对象的构造和析构: 全局对象 C++程序中所有的global objects都被放置在程序的data segment中.如果显式指定给它一个值,此object将以此值为初值.否则object所配置到的 ...

  9. 题解 P1888 【三角函数】

    堆排序万岁! 小金羊又来水题了 #include <iostream> #include <queue> using namespace std; priority_queue ...

  10. hive 一次性命令

    1.用hive查询,而不进入hive cli,查询后的值可以保存到文件中 #使用参数-e [hadoop@bigdata-senior01 ~]$ hive -e "select * fro ...