题目链接

题意

给定二维坐标上的\(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. pip使用国内镜像源

    windows版 1.在windows文件管理器中,输入 %APPDATA% 2.在该目录下新建pip文件夹,然后到pip文件夹里面去新建个pip.ini文件 3.在新建的pip.ini文件中输入以下 ...

  2. 【前端学习笔记04】JavaScript数据通信Ajax方法封装

    //Ajax 方法封装 //设置数据格式 function setData(data){ if(!data){ return ''; } else{ var arr = []; for(k in da ...

  3. 第110天:Ajax原生js封装函数

    一.Ajax的实现主要分为四部分: 1.创建Ajax对象 // 创建ajax对象 var xhr = null; if(window.XMLHttpRequest){ xhr = new XMLHtt ...

  4. CTSC2012-Cheat

    题意 给出一些母01串,多次询问,每次询问一个01串,问一个最大的\(L\),使得可以在询问串中选出若干个不相交的,长度大于等于\(L\)的子串,这些子串都在母串中出现过,且子串的长度和大于等于询问串 ...

  5. BZOJ4887 Tjoi2017可乐(动态规划+矩阵快速幂)

    设f[i][j]为第i天到达j号城市的方案数,转移显然,答案即为每天在每个点的方案数之和.矩乘一发即可. #include<iostream> #include<cstdio> ...

  6. RabbitMQ 使用详细介绍

    1. 实现最简单的队列通信 2. producer端 # !/usr/bin/env python import pika #通过这个实例,先去建立一个socket,默认端口15672 connect ...

  7. 创建Django工程-Day19

    1. 新建一个day19的工程和app01. 2. 新建templates和static的文件夹. 3. 去settings.py中去做配置. 1)注释掉csrf 2)配置模板路径 'DIRS': [ ...

  8. 【转】大数据分析(Big Data OLAP)引擎Dremel, Tenzing 以及Impala

    引自:http://blog.csdn.net/xhanfriend/article/details/8434896 对于数据分析师来说,SQL是主要的语言. Hive为Hadoop提供了支持SQL运 ...

  9. 洛谷 P3723 [AH2017/HNOI2017]礼物 解题报告

    P3723 [AH2017/HNOI2017]礼物 题目描述 我的室友最近喜欢上了一个可爱的小女生.马上就要到她的生日了,他决定买一对情侣手环,一个留给自己,一个送给她.每个手环上各有 \(n\) 个 ...

  10. 洛谷 P3924 康娜的线段树 解题报告

    P3924 康娜的线段树 题目描述 小林是个程序媛,不可避免地康娜对这种人类的"魔法"产生了浓厚的兴趣,于是小林开始教她\(OI\). 今天康娜学习了一种叫做线段树的神奇魔法,这种 ...