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. Xftp安装和使用的视频录制方法

    内容: 1.使用工具 2.操作步骤及方法 视频地址: http://v.youku.com/v_show/id_XMzEwNjg2MTg2NA==.html?spm=a2h3j.8428770.341 ...

  2. 基于 IBM WAS ND v6.1 搭建稳定高效的集群环境

    如今的电子商务及电子政务应用系统的发展已经到了一个新的阶段,应用系统的成熟度和可用性都达到了更高的水准.因此庞大的部署规模和海量的用户访问成为目前大型电子商务及电子政务应用系统的显著特征.在这样的情况 ...

  3. 使用命令virsh管理网络设备,创建桥设备 和 使用virt-manager创建虚拟机

    # 1:查看网卡接口 virsh iface-list Name State MAC Address ------------------------------------------------- ...

  4. Scrum团队成立及《构建之法》第六、七章读后感

    5.Scrum团队成立 5.1 团队名称:喳喳      团队目标:突破渣渣      团队口号:吱吱喳喳      团队照: 5.2 角色分配 产品负责人: 112冯婉莹 Scrum Master: ...

  5. Alpha阶段敏捷冲刺 DAY5

    一.举行站立式例会 1.今天我们利用晚上的时间开展了站立会议,总结了一下之前工作的问题,并且制定了明天的计划. 2.站立式会议照片 二.团队报告 1.昨日已完成的工作 (1)改进了程序算法 (2)优化 ...

  6. linux 下svn忽略文件

    假设想忽略文件temp 1. cd到temp所在的目录下: 2. svn propedit svn:ignore . 注意:请别漏掉最后的点(.表示当前目录),如果报错请看下面 3. 打开的文件就是忽 ...

  7. C语言为运算及 两个变量的赋值问题

    #include <stdio.h>#define ARRAY_SIZE 10int main() {    int arr[ARRAY_SIZE] = {51,116,53,120,85 ...

  8. MySQL 分组排序问题

    SQL好久不写了,有些生疏了,一个分组排序问题想了快半天,整理下. 学生表 CREATE TABLE `t_student` ( `id` bigint(20) NOT NULL AUTO_INCRE ...

  9. CERC2013(C)_Magical GCD

    题意是这样的,给你一个序列a[i],需要你选一段连续的序列a[i]到a[j],使得长度乘以这个段的gcd最大. 一开始总是以为是各种神奇的数据结构,诶,后来才发现,机智才是王道啊. 可以这样考虑,每次 ...

  10. compareTo 返回为整数 调用者比参数大;返回负数 调用者比参数小

    compareTo 返回为整数 调用者比参数大;返回负数 调用者比参数小