首先我们如果满足三缺一,那么必有同行和同列的点

如果两行有同列的数,我们可以设想,他们最后会全部填充成为两者啥都有的情况

显然这个是个并查集

现在我们有了很多集合,每个集合自己可以进行三缺一操作,但是集合有缺陷,集合里面的人都没有的列数,那就没法搞

可以贪心的想,一共k个集合的话,把k个集合连接起来需要k-1个新点,如果还有列没有,那就需要这些列需要新店

除此之外,一开始没有讨论有些行压根没有点,这些行也需要点去开辟疆土

综上所述,一开始论述的时候将行和列交换也是合理的

人总喜欢在伤心,劳累,挫折时放纵自己,但这之后把你引向深渊

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
typedef long long ll;
const int N = 200005;
const int INF = 0x3f3f3f3f; int f[N]; //col
int find(int x) { return f[x] == x ? x : (f[x] = find(f[x])); } vector<int> row[N];
vector<int> col[N]; vector<int> part[N];
int has[N]; int tag[N];
int main() {
int n, m, q;
while(~scanf("%d %d %d", &n, &m, &q)) {
for(int i = 1; i <= m; ++i) f[i] = i;
for(int i = 0; i < q; ++i) {
int a, b;
scanf("%d %d", &a, &b);
row[a].push_back(b);
tag[a] ++;
col[b].push_back(a);
has[b] = 1;
}
for(int i = 1; i <= n; ++i) {
for(int j = 1; j < row[i].size(); ++j) {
int t1 = row[i][0];
int t2 = row[i][j];
int f1 = find(t1); int f2 = find(t2);
if(f1 != f2) {
f[f2] = f1;
}
}
} for(int i = 1; i <= m; ++i) {
int tt = find(i);
part[tt].push_back(i);
} int cnt = 0; int cntPart = 0;
for(int i = 1; i <= m; ++i) {
if(!has[i]) continue;
if(part[i].size() > 0) {
cntPart ++;
cnt += part[i].size();
}
} int result = 0;
for(int i = 1; i <= n; ++i) {
if(!tag[i])
result ++;
}
// printf("%d\n", cnt);
printf("%d\n", result + cntPart - 1 - cnt + m);
}
return 0;
}

Codeforces Round #500 (Div. 2) D - Chemical table的更多相关文章

  1. Codeforces Round #500 (Div. 2) [based on EJOI]

    Codeforces Round #500 (Div. 2) [based on EJOI] https://codeforces.com/contest/1013 A #include<bit ...

  2. Codeforces Round 500 (Div 2) Solution

    从这里开始 题目地址 瞎扯 Problem A Piles With Stones Problem B And Problem C Photo of The Sky Problem D Chemica ...

  3. Codeforces Round #323 (Div. 2) C. GCD Table 暴力

    C. GCD Table Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/583/problem/C ...

  4. Codeforces Round #323 (Div. 2) C. GCD Table map

    题目链接:http://codeforces.com/contest/583/problem/C C. GCD Table time limit per test 2 seconds memory l ...

  5. Codeforces Round #323 (Div. 2) C.GCD Table

    C. GCD Table The GCD table G of size n × n for an array of positive integers a of length n is define ...

  6. Codeforces Round #323 (Div. 1) A. GCD Table

    A. GCD Table time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  7. Codeforces Round #140 (Div. 1) D. The table 构造

    D. The table 题目连接: http://www.codeforces.com/contest/226/problem/D Description Harry Potter has a di ...

  8. Codeforces Codeforces Round #319 (Div. 2) A. Multiplication Table 水题

    A. Multiplication Table Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/57 ...

  9. Codeforces Round #256 (Div. 2) D. Multiplication Table(二进制搜索)

    转载请注明出处:viewmode=contents" target="_blank">http://blog.csdn.net/u012860063?viewmod ...

随机推荐

  1. Springboot时间参数格式化

    @Configuration public class DateTimeFormatConfiguration extends WebMvcConfigurerAdapter { @Value(val ...

  2. Eclipse中修改git地址、用户、密码

    1. 修改Url Window > Preferences > Team > Git > Configuration > Repository Settings 2. 修 ...

  3. Decorator(装饰)模式

    1. 概述 若你从事过面向对象开发,实现给一个类或对象增加行为,使用继承机制,这是所有面向对象语言的一个基本特性.如果已经存在的一个类缺少某些方法,或者须要给方法添加更多的功能(魅力),你也许会仅仅继 ...

  4. linux查看nginx、apache、php、php-fpm、mysql及配置项所在目录

    可以先总结下:大都是先用 which 获取目录:然后再获取配置项位置: which  mysql /usr/bin/mysql /usr/bin/mysql --help | grep -A1 'De ...

  5. RedirectAttributes 之 IE8请求跳转失败

    1.时间真快,一晃又快冬天了,下了第一场雪.雪花漫漫,堵车悠悠. 2.这次遇到这样一个问题,就是RedirectAttributes传递数据参数,如果参数数据过大,在IE8浏览器时候会跳转不过去.其实 ...

  6. angular1.x todolist 实现

    将要计划完成事的列表存在localStroage ,实现本地同步删除,同步增加. <!DOCTYPE html> <html lang="zh" ng-app=& ...

  7. Redis笔记 -- make编译安装报错记录2则(一)

    1.Redis的获取与安装,目前最新稳定版本为4.0.10 Redis:  https://redis.io/download GitHub:  https://github.com/antirez/ ...

  8. python3 str各个功能记录

    capitalize() 将字符串的第一个字符转换为大写 center(width, fillchar) 返回一个指定的宽度 width 居中的字符串,fillchar 为填充的字符,默认为空格. c ...

  9. 浅谈ruby中的block及yield

    今天写代码的时候遇到了block_given?,查阅了一下语法书中并没有相关的知识点,于是翻阅微博及结合工作中的实际代码,整理如下: 一.“块”: ruby的块指的是什么? 是 do~end中间的那部 ...

  10. Python学习:14.Python面向对象(一)

    一.面向对象简介 Python设计之初,就是一门面向对象的语言,在Python中一切皆对象,而且在Python中创建一个对象也很简单,今天我们就来学习一下Python的面向对象的知识. 二.两种编程方 ...