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. 修改anocanda的channel

    http://blog.csdn.net/mtj66/article/details/57074986

  2. Zero Array---思维题

    链接        submit B. Zero Array time limit per test 1 second memory limit per test 256 megabytes inpu ...

  3. Swoft2.x 小白学习笔记 (一) ---控制器

    Swoft通过官方文档进行学习,这里不做介绍,直接上手. 涉及到Swoft方面:(配置.注意的坑) 1.控制器(路由.验证器.中间件) 2.mysql  (Model使用).Redis配置及通用池 3 ...

  4. docker入门到放弃

    1.容器简介 Docker是一个开源的应用容器引擎,使用Go语言开发,基于Linux内核的cgroup,namespace,Union FS等技术,对应用进程进行封装隔离,并且独立于宿主机与其他进程, ...

  5. py2和py3之间的不同

    1.print函数 很琐碎,而 print 语法的变化可能是最广为人知的了,但是仍值得一提的是: Python 2 的 print 声明已经被 print() 函数取代了,这意味着我们必须包装我们想打 ...

  6. PostgreSQL查看表、表索引、视图、表结构以及参数设置

    -- 表索引select * from pg_indexes where tablename='person_wechat_label';select * from pg_statio_all_ind ...

  7. CNN网络结点计算总结(1998)

    图 来源:Gradient-Based Learning Applied to Document Recognition 参阅CSDN:https://blog.csdn.net/dcxhun3/ar ...

  8. nop4.1学习ServiceCollectionExtensions(二)(ioc,ef,ef连接的实现)

    这个是获取程序路径,并初始化文件管理类 初始化插件管理 接下来就是注册服务和autoafc 在INopStartup配置sql连接,插件,mvc等 配置了sql连接 数据库的配置类 在AddAutoM ...

  9. form表单中的enctype 属性以及post请求里Content-Type方式

    对于form表单中的enctype 属性之前理解的一般,就知道是类似于一种编码形式.后来公司做一个form表单提交数据的时候,重点是这个form表单里有文件上传,而我又要用vue来模拟form表单提交 ...

  10. 正着打星星(js)

    //让用户输入行数,使用for循环嵌套打出正着的星星来,行数等于用户输入的数字 //例如:用户输入6 // * // *** // ***** // ******* // ********* // * ...