codeforces 872E. Points, Lines and Ready-made Titles
http://codeforces.com/contest/872/problem/E
2 seconds
256 megabytes
standard input
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.
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 xi, yi ( - 109 ≤ xi, yi ≤ 109) — coordinates of the i-th point.
It is guaranteed that all points are distinct.
Print the number of possible distinct pictures modulo 109 + 7.
4
1 1
1 2
2 1
2 2
16
2
-1 -1
0 1
9
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的更多相关文章
- 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 ...
- Codeforces 870E Points, Lines and Ready-made Titles:并查集【两个属性二选一】
题目链接:http://codeforces.com/problemset/problem/870/E 题意: 给出平面坐标系上的n个点. 对于每个点,你可以画一条经过这个点的横线或竖线或什么都不画. ...
- Codeforces 870E Points, Lines and Ready-made Titles 计数
题目链接 题意 给定二维坐标上的\(n\)个点,过每个点可以 画一条水平线 或 画一条竖直线 或 什么都不画,并且若干条重合的直线被看做同一条.问共可能得到多少幅不同的画面? 题解 官方题解 仆の瞎扯 ...
- 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 ...
- 【题解】Points, Lines and Ready-made Titles Codeforces 871C 图论
Prelude 真是一道好题,然而比赛的时候花了太多时间在B题上,没时间想这个了QAQ. 题目链接:萌萌哒传送门(.^▽^) Solution 观察样例和样例解释,我们发现,假如有四个点,恰好占据在某 ...
- CodeForces 19D Points
Pete and Bob invented a new interesting game. Bob takes a sheet of paper and locates a Cartesian coo ...
- R语言:多个因变量时,如何在plot函数中画多条曲线(plot,points,lines,legend函数)
最近阅读一篇文献<Regional and individual variations in the function of the human eccrine sweat gland>, ...
- CodeForces 19D Points (线段树+set)
D. Points time limit per test 2 seconds memory limit per test 256 megabytes input standard input out ...
- 『ACM C++』 Codeforces | 1066A - Points in Segments
大一生活真 特么 ”丰富多彩“ ,多彩到我要忙到哭泣,身为班长,很多班级的事情需要管理,也是,什么东西都得体验学一学,从学生会主席.团委团总支.社团社长都体验过一番了,现在差个班长也没试过,就来体验了 ...
随机推荐
- 【探路者】团队Alpha周贡献分数分配结果
经本组成员商议,根据老师提供的分数,(每人携带10分进入团队,[探路者]团队7人,共计35分). 本周每位同学携带10分进入组内,7人共计70分.分数公布如下: 吴雨丹 15分 贾雅杰 12分 蔺依铭 ...
- int 和 Integer的区别
int是基本类型,默认值为0,int a=5;a只能用来计算,一般作为数值参数. Integer是引用类型,默认值为null, Integer b=5;b是一个对象,它可以有很多方法,一般做数值转换, ...
- alpha6/10
队名:Boy Next Door 燃尽图 晗(组长) 今日完成 学习了css的一些基本操作. 明日工作 抽空把javascript的基本操作学习一下 还剩下哪些任务 微信API还有京东钱包的API. ...
- lintcode-496-玩具工厂
496-玩具工厂 工厂模式是一种常见的设计模式.请实现一个玩具工厂 ToyFactory 用来产生不同的玩具类.可以假设只有猫和狗两种玩具. 您在真实的面试中是否遇到过这个题? Yes 样例 ToyF ...
- Markdown github 风格语法
某些效果cnblog无法支持,见 https://github.com/tanghammer/note/blob/master/Markdown%20github%E9%A3%8E%E6%A0%BC% ...
- 3dContactPointAnnotationTool开发日志(二五)
记录一下当前进度:
- Spring MVC @RequestParam @RequestHeader @CookieValue用法
摘要: package com.hust.springmvc1; import org.springframework.stereotype.Controller; import org.spring ...
- Java 调用 google 翻译
1.Java代码 public class Translator { public String translate(String langFrom, String langTo, String wo ...
- TDDL调研笔记
一,TDDL是什么 Taobao Distributed Data Layer,即淘宝分布式数据层,简称TDDL .它是一套分布式数据访问引擎 淘宝一个基于客户端的数据库中间件产品 基于JDBC规范, ...
- BZOJ3711 PA2014Druzyny(动态规划+cdq分治+线段树)
显然可以dp:设f[i]为前i个人最多能分多少组,则f[i]=max{f[j]}+1 (cmax<=i-j<=dmin). 容易发现d的限制是一段连续区间,二分或者随便怎么搞都行.c则有点 ...