OvO http://codeforces.com/contest/871/problem/C

  ( Codeforces Round #440 (Div. 1, based on Technocup 2018 Elimination Round 2) - C )

  问题可以转化为:这些点可以产生的横线与竖线的出现情况

  首先,对于二维坐标系中的每一行中,对于每个点,如果右边有点,则从该点向右边这个点(相邻的那个点)连一条边(连一条单向的),

  对于每一列中,对于每个点,如果该点下面有点,则向下边这个点(相邻的那个点)连一条边(同上)

  (具体实现可以通过排序)

  然后对于每个点,将与之相连的点并查集合并,合并时如果发现成环,则这个集合tag=1,否则tag=0。

  算出每个集合中所有点所占据的不重复的行列数,记为dif。

  对于每个集合,如果这个集合中tag=1,那么这个集合所产生的答案为 2^dif,如果tag=0,那么这个集合所产生的答案为 (2^dif)-1 ,(原因的话,画图可以得出)

  每个集合的答案是独立的,所以取他们的积

  

  

#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <set>
#include <map> using namespace std; typedef long long ll; const int N=4e5+44;
const int mod=1e9+7;
const int bas=1e9+44; struct node{
int u,v;
int next;
} edge[2*N]; struct Point
{
int x,y,id;
} p[N]; int head[N],num,tag[N],cnt[N],dif[N];
int n,ma[N];
set<int> sx[N],sy[N]; int findma(int x)
{
if(ma[x]==x)
return x;
return ma[x]=findma(ma[x]);
} bool cmp1(Point a,Point b)
{
if(a.x==b.x)
return a.y<b.y;
return a.x<b.x;
} bool cmp2(Point a,Point b)
{
if(a.y==b.y)
return a.x<b.x;
return a.y<b.y;
} bool cmp(Point a,Point b)
{
return a.id<b.id;
} void addedge(int u,int v)
{
edge[num].u=u;
edge[num].v=v;
edge[num].next=head[u];
head[u]=num++;
} void init()
{
int i,j;
num=0;
memset (head,-1,sizeof(head));
for(i=1;i<=n;i++)
ma[i]=i,cnt[i]=1;
memset(tag,0,sizeof(tag));
memset(dif,0,sizeof(dif));
for(i=1;i<=n;i++)
sx[i].clear(),sy[i].clear();;
} long long pr(int a, int b)
{
long long r=1,base=a;
while(b!=0)
{
if(b&1)
r=(r*base)%mod;
base=(base*base)%mod;
b>>=1;
}
return r;
} void solve()
{
int i,j,a,b,pa,pb;
ll ans=1,tmp;
for(i=1;i<=n;i++)
{
for(j=head[i];j!=-1;j=edge[j].next)
{
a=i; b=edge[j].v;
pa=findma(a); pb=findma(b);
if(pa==pb)
{
tag[pa]=1;
}
else
{
ma[pa]=pb;
tag[pb]=tag[pb]|tag[pa];
cnt[pb]+=cnt[pa];
}
}
}
for(i=1;i<=n;i++)
{
a=i; pa=findma(a);
tmp=p[a].x;
if(sx[pa].find(tmp)==sx[pa].end())
{
dif[pa]++;
sx[pa].insert(tmp);
}
tmp=p[a].y;
if(sy[pa].find(tmp)==sy[pa].end())
{
dif[pa]++;
sy[pa].insert(tmp);
}
}
for(i=1;i<=n;i++)
if(ma[i]==i)
{
tmp=pr(2,dif[i]);
if(tag[i]==0) tmp--;
ans=ans*tmp%mod;
}
printf("%I64d\n",ans);
} int main()
{
int i,j;
scanf("%d",&n);
init();
for(i=1;i<=n;i++)
{
scanf("%d%d",&p[i].x,&p[i].y);
p[i].id=i;
}
sort(p+1,p+n+1,cmp1);
for(i=1;i<n;i++)
if(p[i].x==p[i+1].x)
addedge(p[i].id,p[i+1].id);
sort(p+1,p+n+1,cmp2);
for(i=1;i<n;i++)
if(p[i].y==p[i+1].y)
addedge(p[i].id,p[i+1].id);
sort(p+1,p+n+1,cmp);
solve();
return 0;
}

  

Codeforces 871C 872E Points, Lines and Ready-made Titles的更多相关文章

  1. codeforces 872E. Points, Lines and Ready-made Titles

    http://codeforces.com/contest/872/problem/E E. Points, Lines and Ready-made Titles time limit per te ...

  2. 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 ...

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

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

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

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

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

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

  6. codeforces 19D D. Points 树套树

    D. Points Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/19/problem/D De ...

  7. Codeforces 593B Anton and Lines

    LINK time limit per test 1 second memory limit per test 256 megabytes input standard input output st ...

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

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

  9. CodeForces - 1047B Cover Points

    B. Cover Points time limit per test1 second memory limit per test256 megabytes inputstandard input o ...

随机推荐

  1. 关于 resultType 与 parameterType 的基本使用的区别

    以下关于      resultType    与    parameterType   的基本使用的区别 : 1.使用  resultType :   主要针对于从数据库中提取相应的数据出来 2.使 ...

  2. Linux 防火墙设置常用指令

    查看防火墙状态命令: service firewalld status systemctl status firewalld 结果: 其中:   enabled:开机启动(开机不启动是disabled ...

  3. 小记--------sqoop的简单从mysql导入到hbase操作

    sqoop import -D sqoop.hbase.add.row.key=true                        //是否将rowkey相关字段列入列族中,默认为false :该 ...

  4. webpack权限控制

    const type= "a"; const menusConfig = { a: ["activity"], b: ["activity" ...

  5. winform messageBox.Show()

    MessageBox.Show(" 5 个参数...... ",     " 亮仔提示",     MessageBoxButtons.OKCancel,    ...

  6. c#调用带用户名密码验证的wsdl

    之前记录过一篇添加带验证的webservice,但是公司的另一个项目是.net framework2.0的项目,没有服务引用,只能添加web引用. 现在记录和分享一下方法: 先添加web引用,选择ws ...

  7. 【原创】大数据基础之ETL vs ELT or DataWarehouse vs DataLake

    ETL ETL is an abbreviation of Extract, Transform and Load. In this process, an ETL tool extracts the ...

  8. 【原创】大叔经验分享(63)kudu vs parquet

    一 对比 存储空间对比: 查询性能对比: 二 设计方案 将数据拆分为:历史数据(hdfs+parquet+snappy)+ 近期数据(kudu),可以兼具各种优点: 1)整体低于10%的磁盘占用: 2 ...

  9. JavaScript例子2-使一个特定的表格隔行变色

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  10. SpringBoot整合MyBatis的分页插件PageHelper

    1.导入依赖(maven) <dependency> <groupId>com.github.pagehelper</groupId> <artifactId ...