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 ^ n - 1
否则是2 ^ n。 各个联通块乘起来就是答案。
#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ull unsigned long long
using namespace std; const int N = 4e5 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ;
const double eps = 1e-; int n, x[N], y[N], hs[N], tot;
int bin[N], fa[N], ecnt[N], pcnt[N]; int getRoot(int x) {
return x == fa[x] ? x : fa[x] = getRoot(fa[x]);
} int main() {
for(int i = bin[] = ; i < N; i++) bin[i] = bin[i - ] * % mod;
scanf("%d", &n);
for(int i = ; i <= n; i++) {
scanf("%d%d", &x[i], &y[i]);
hs[++tot] = x[i];
hs[++tot] = y[i];
}
sort(hs + , hs + + tot);
tot = unique(hs + , hs + + tot) - hs - ;
for(int i = ; i <= n; i++) {
x[i] = lower_bound(hs + , hs + + tot, x[i]) - hs;
y[i] = lower_bound(hs + , hs + + tot, y[i]) - hs;
}
for(int i = ; i <= * tot; i++) fa[i] = i, ecnt[i] = , pcnt[i] = ;
for(int i = ; i <= n; i++) {
int X = getRoot(x[i]);
int Y = getRoot(y[i] + tot);
if(X == Y) {
ecnt[X]++;
} else {
ecnt[X] += ecnt[Y] + ;
pcnt[X] += pcnt[Y];
fa[Y] = X;
}
}
LL ans = ;
for(int i = ; i <= * tot; i++) {
if(i != fa[i]) continue;
if(ecnt[i] < pcnt[i]) ans = (ans * (bin[pcnt[i]] - + mod) % mod) % mod;
else ans = (ans * bin[pcnt[i]]) % mod;
}
printf("%lld\n", ans);
return ;
} /*
*/
Codeforces Round #440 (Div. 1, based on Technocup 2018 Elimination Round 2) C - Points, Lines and Ready-made Titles的更多相关文章
- Codeforces Round #440 (Div. 2, based on Technocup 2018 Elimination Round 2)
A. Search for Pretty Integers 题目链接:http://codeforces.com/contest/872/problem/A 题目意思:题目很简单,找到一个数,组成这个 ...
- Codeforces Round #440 (Div. 2, based on Technocup 2018 Elimination Round 2) D. Something with XOR Queries
地址:http://codeforces.com/contest/872/problem/D 题目: D. Something with XOR Queries time limit per test ...
- Codeforces Round #440 (Div. 2, based on Technocup 2018 Elimination Round 2) C. Maximum splitting
地址: 题目: C. Maximum splitting time limit per test 2 seconds memory limit per test 256 megabytes input ...
- ACM-ICPC (10/15) Codeforces Round #440 (Div. 2, based on Technocup 2018 Elimination Round 2)
A. Search for Pretty Integers You are given two lists of non-zero digits. Let's call an integer pret ...
- Codeforces Round #434 (Div. 2, based on Technocup 2018 Elimination Round 1)&&Codeforces 861C Did you mean...【字符串枚举,暴力】
C. Did you mean... time limit per test:1 second memory limit per test:256 megabytes input:standard i ...
- Codeforces Round #434 (Div. 2, based on Technocup 2018 Elimination Round 1)&&Codeforces 861B Which floor?【枚举,暴力】
B. Which floor? time limit per test:1 second memory limit per test:256 megabytes input:standard inpu ...
- Codeforces Round #434 (Div. 2, based on Technocup 2018 Elimination Round 1)&&Codeforces 861A k-rounding【暴力】
A. k-rounding time limit per test:1 second memory limit per test:256 megabytes input:standard input ...
- Codeforces Round #434 (Div. 2, based on Technocup 2018 Elimination Round 1)
A. k-rounding 题目意思:给两个数n和m,现在让你输出一个数ans,ans是n倍数且末尾要有m个0; 题目思路:我们知道一个数末尾0的个数和其质因数中2的数量和5的数量的最小值有关系,所以 ...
- 【模拟】 Codeforces Round #434 (Div. 1, based on Technocup 2018 Elimination Round 1) C. Tests Renumeration
题意:有一堆数据,某些是样例数据(假设X个),某些是大数据(假设Y个),但这些数据文件的命名非常混乱.要你给它们一个一个地重命名,保证任意时刻没有重名文件的前提之下,使得样例数据命名为1~X,大数据命 ...
随机推荐
- 【题解】 [ZJOI2006]书架 (Splay)
懒得复制,戳我戳我 Solution: 还是一个\(Splay\),我们只用多存一个值\(rad\)来维护二叉树,然后用数组存下每个书对应的值是多少 \(Top\)操作,我是把\(s\)旋转到根节点, ...
- CentOS服务器配置SSH免密码登录
由于工作需要,经常要登录到多台服务器远程操作,每次都是ssh user@host:port 再输入密码,时间长了,难免觉得乏味-- 故而从度娘那里扒来了一些让SSH免密码登录的办法,其实这也是使用Gi ...
- 洛谷 P1993 小K的农场 解题报告
P1993 小K的农场 题目描述 小K在MC里面建立很多很多的农场,总共n个,以至于他自己都忘记了每个农场中种植作物的具体数量了,他只记得一些含糊的信息(共m个),以下列三种形式描述: 农场a比农场b ...
- 使用Rider写一个C#的Hello World程序
1. 安装Rider 首先到Jetbrains官网下载Rider:https://www.jetbrains.com/rider/ 然后到IntelliJ IDEA 注册码获得注册码. 2. 安装do ...
- Libre 6005 「网络流 24 题」最长递增子序列 / Luogu 2766 最长递增子序列问题(网络流,最大流)
Libre 6005 「网络流 24 题」最长递增子序列 / Luogu 2766 最长递增子序列问题(网络流,最大流) Description 问题描述: 给定正整数序列x1,...,xn . (1 ...
- ctrl+E 快速显示当前打开的编辑列表
ctrl+E 快速显示当前打开的编辑列表
- NB-IoT 的“前世今生”
作者:个推B2D研发工程师 海晏 根据<爱立信2018移动报告>(Ericsson Mobility Report,June 2018)的预测,蜂窝物联网设备连接数将在2023年达到35亿 ...
- 弹指之间 -- Slow Soul
CHAPTER 16 慢灵魂乐 Slow Soul (8Beat) Slow Soul每小节内几乎都是以8分音符弹奏,又称之为8Beat节奏,80左右的速度最能表现此节奏特色. 示例曲目: 拥抱
- String的用法------程序猿的双十一
小感慨:我就静静的写着代码玩,度过一年一度的双十一,今晚就更新进度,整理笔记. package com.mon11.day10; import static org.junit.Assert.*; i ...
- dedecms列表页调用文章正文内容的方法
谁说dede:list 标签不能调用body内容,现在就告诉你,直接就可以调用 第一步,打开后台 核心-->频道模型-->内容模型管理-->普通文章,在列表附加字段中添加body. ...