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. LeetCode 888. Fair Candy Swap(C++)

    题目: Alice and Bob have candy bars of different sizes: A[i] is the size of the i-th bar of candy that ...

  2. KNN算法之图像处理二

    1.看了诸多博客,初步得到结论是:KNN不适合做图像分类. 2.如果偏要用此方法进行图像分类,距离计算为:对应的每个像素代表的像素值进行绝对差值计算,最后求和.这就是“图像的距离”

  3. swift - tabBar图片设置的一些注意点

    图片大小尺寸 刚刚开始接触的话,从美工那边拿来的图标大小一般都是偏大的,就像这样: 在此建议,tabBar的图标大小可以是32*32,个人感觉效果不错 图片的颜色问题 如上图所示,该图标的期望颜色(也 ...

  4. Java对象创建过程补遗

    一.static修饰的东东是属于这个类的,是所有的该类的实例共享的,因此它们的初始化先于实例对象的初始化. 二.Java中没有静态构造方法,但是有静态代码块.当类中同时存在静态代码块和静态成员变量声明 ...

  5. java分页算法

    int totalPageNum = (totalRecord  +  pageSize  - 1) / pageSize;

  6. C语言添加宏开关

    原文地址:http://blog.csdn.net/cp1300/article/details/7773239 我们在写程序的时候,总是或多或少会加入一些printf之类的语句用于输出调试信息,但是 ...

  7. Hibernate 中一级缓存和快照区的理解

    刚刚开始的时候觉得这个快照区很难理解,在网上看了很多博客之后,开始明白了.我是结合 ADO.NET 理解的,在ADO.NET 中有一个类, 叫 SqlCommandBuilder,在我看来,他就是 A ...

  8. 分享:50行代码监听watch小程序的globalData

    监听方法: // 在任何组件.页面,例如页面 const app = getApp( ); Page({ onLoad: function( ) { app.watch$('role', ( val, ...

  9. 【bzoj5206】[Jsoi2017]原力 根号分治+STL-map

    题目描述 一个原力网络可以看成是一个可能存在重边但没有自环的无向图.每条边有一种属性和一个权值.属性可能是R.G.B三种当中的一种,代表这条边上原力的类型.权值是一个正整数,代表这条边上的原力强度.原 ...

  10. 什么是P问题,NP问题和NPC问题

    转载自:Matrix67的博客 什么是P问题.NP问题和NPC问题 这或许是众多OIer最大的误区之一.    你会经常看到网上出现“这怎么做,这不是NP问题吗”.“这个只有搜了,这已经被证明是NP问 ...