题目链接

题意

给定二维坐标上的\(n\)个点,过每个点可以 画一条水平线 或 画一条竖直线 或 什么都不画,并且若干条重合的直线被看做同一条。问共可能得到多少幅不同的画面?

题解

官方题解

仆の瞎扯

bzoj 1854的并查集思路蜜汁契合

// 看完了题解的我这样想道

首先显然可以将图分为若干个联通块。

且慢,哪里来的图?

那就先考虑建图?

不急不急,先来想想看每一个联通块的性质。

如果该联通块中有环的话,肯定每条边都能取到;如果联通块是一棵树,那么必有一条边取不到(具体阐述见上bzoj 1854),所以只需要知道

  1. 这个联通块中有多少条边
  2. 这个联通块是不是环

这两个信息就可以了

那么可以直接上并查集。

什么样的点可以并到一起呢?横坐标相同的或者纵坐标相同的。

有没有环怎么维护呢?看有没有加进去的边的端点本身就在一个集合里。

联通块中边的数目又怎么知道呢?这倒还挺有意思的,其实只要直接看出现过多少个横坐标或者纵坐标就可以了,因为一个横坐标或者一个纵坐标就代表一条可以选的直线,所以这块联通块的贡献就是\(2^{x+y}或者2^{x+y}-1\)。

然后呢?就做完了。

然而呢?比赛结束。一天了。

然后再推荐一下葫芦爷的题解太强辣

Code

#include <bits/stdc++.h>
#define maxn 100010
using namespace std;
typedef long long LL;
const LL mod = 1e9+7;
struct node {
int x, y;
}a[maxn];
int fa[maxn], sz[maxn], f[maxn], id[maxn], m[maxn];
bool circ[maxn], vis[maxn];
vector<int> v[maxn];
set<int> sx, sy;
bool cmp1(int i, int j) {
return a[i].x < a[j].x || (a[i].x == a[j].x && a[i].y < a[j].y);
}
bool cmp2(int i, int j) {
return a[i].y < a[j].y || (a[i].y == a[j].y && a[i].x < a[j].x);
}
LL poww(LL a, LL b) {
LL ret = 1;
while (b) {
if (b & 1) (ret *= a) %= mod;
(a *= a) %= mod;
b >>= 1;
}
return ret;
}
int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
void unionn(int a, int b) {
a = find(a), b = find(b);
if (a == b) { circ[a] = true; return; }
if (sz[a] > sz[b]) swap(a, b);
fa[a] = b; sz[b] += sz[a];
circ[b] |= circ[a];
}
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%d%d", &a[i].x, &a[i].y);
}
for (int i = 0; i < n; ++i) id[i] = i;
for (int i = 0; i < n; ++i) fa[i] = i, sz[i] = 1; sort(id, id+n, cmp1);
for (int i = 1; i < n; ++i) {
if (a[id[i]].x == a[id[i-1]].x) unionn(id[i-1], id[i]);
}
sort(id, id+n, cmp2);
for (int i = 1; i < n; ++i) {
if (a[id[i]].y == a[id[i-1]].y) unionn(id[i-1], id[i]);
}
for (int i = 0; i < n; ++i) fa[i] = find(i); int tot = -1;
for (int i = 0; i < n; ++i) {
if (!vis[fa[i]]) vis[fa[i]] = true, f[++tot] = fa[i], m[fa[i]] = tot;
v[m[fa[i]]].push_back(i);
}
LL ans = 1;
for (int i = 0; i <= tot; ++i) {
sx.clear(), sy.clear();
for (auto idx : v[i]) {
sx.insert(a[idx].x), sy.insert(a[idx].y);
}
LL mul = poww(2, sx.size()+sy.size());
if (!circ[f[i]]) (mul += mod-1) %= mod;
(ans *= mul) %= mod;
}
printf("%I64d\n", ans);
return 0;
}

Codeforces 870E Points, Lines and Ready-made Titles 计数的更多相关文章

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

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

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

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

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

  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. display:table的几个妙用:垂直居中、浮动……

    一.为什么不用table系表格元素? 目前,在大多数开发环境中,已经基本不用table元素来做网页布局了,取而代之的是div+css,那么为什么不用table系表格元素呢? 1.用DIV+CSS编写出 ...

  2. 移动端开发-viewport

    1.viewport viewport 即设备 屏幕上显示网页的区域.因为移动设备屏幕比较小,为了能让移动设备能够显示更多内容,默认设置的viewport 并不是屏幕真是像素点的宽度,一般为980px ...

  3. BZOJ4999 This Problem Is Too Simple!(树上差分+dfs序+树状数组)

    对每个权值分别考虑.则只有单点加路径求和的操作.树上差分转化为求到根的路径和,子树加即可.再差分后bit即可.注意树上差分中根的父亲是0,已经忘了是第几次因为这个挂了. #include<ios ...

  4. [cogs1065]绿豆蛙的归宿

    1065. [Nescafe19] 绿豆蛙的归宿 [题目描述] 给出一个有向无环的连通图,起点为1终点为N,每条边都有一个长度.绿豆蛙从起点出发,走向终点.到达每一个顶点时,如果有K条离开该点的道路, ...

  5. [AT2557] [arc073_c] Ball Coloring

    题目链接 AtCoder:https://arc073.contest.atcoder.jp/tasks/arc073_c 洛谷:https://www.luogu.org/problemnew/sh ...

  6. redis2.4.conf配置文件中文释意

    # Redis示例配置文件 # 注意单位问题:当需要设置内存大小的时候,可以使用类似1k.5GB.4M这样的常见格式: # # 1k => 1000 bytes # 1kb => 1024 ...

  7. 20135239益西拉姆 Linux内核分析 汇编一个简单的c程序并分析其指令过程

    益西拉姆+<Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000 第一周linux内核分析 学习笔记 一.计算机 ...

  8. mysql三-2:数据类型

    一 介绍 存储引擎决定了表的类型,而表内存放的数据也要有不同的类型,每种数据类型都有自己的宽度,但宽度是可选的 详细参考: http://www.runoob.com/mysql/mysql-data ...

  9. spoj694 DISUBSTR - Distinct Substrings

    Given a string, we need to find the total number of its distinct substrings. Input T- number of test ...

  10. [ldap]slapcat/ldapsearch与ldap备份

    http://serverfault.com/questions/577356/ldap-backup-with-slapcat-vs-ldapsearch Used: openldap-server ...