给你一个网格(n<=2000,m<=2000),有一些炸弹,你可以选择一个空的位置,再放一个炸弹并将其引爆,一个炸弹爆炸后,其所在行和列的所有炸弹都会爆炸,连锁反应。

问你所能引爆的最多炸弹数。

转化成:

将行列当成点,炸弹当成边,然后你可以给这个二分图加1条边,问你最大的连通块的边的数量。

可以通过枚举所有可以建的边,通过并查集来尝试更新答案。由于一条边必然会让总度数+2,所以一个连通块的边数是所有点的度数之和/2。

并查集不必要动态维护集合的大小,一开始就建好并查集,提前统计好即可。

最后枚举的时候不会再在并查集之间再连边了,只会直接去更新答案。

队友的代码:

#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int Ans,num[6000],a[2003][2003],fa[6000],ans[6000],n,m,ansx,ansy;
char ch;
int get(int x) {
return fa[x]==x?x:fa[x]=get(fa[x]);
}
void un(int x,int y)
{
int X=get(x),Y=get(y);
if(X!=Y) fa[X]=Y;
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;++i)
{
for(int j=1;j<=m;++j)
{
while(ch=getchar(),ch!='+'&&ch!='.');
a[i][j]=ch;
if(ch=='+')
{
num[i]++;
num[j+n]++;
}
}
}
Ans=0;
for(int i=1;i<=n+m;++i)
{
fa[i]=i;
}
for(int i=1;i<=n;++i)
for(int j=1;j<=m;++j)
{
if(a[i][j]=='+')
{
un(i,j+n);
}
}
for(int i=1;i<=n+m;++i)
{
ans[get(i)]+=num[i];
}
for(int i=1;i<=n;++i)
for(int j=1;j<=m;++j)
{
if(a[i][j]=='.')
{
int nowans=ans[get(i)];
if(get(i)!=get(j+n))
{
nowans+=ans[get(j+n)];
}
if(nowans/2>Ans)
{
Ans=nowans/2;
ansx=i;
ansy=j;
}
}
}
printf("%d\n",Ans);
if(Ans)
{
printf("%d %d\n",ansx,ansy);
}
return 0;
}

【二分图】【并查集】XVII Open Cup named after E.V. Pankratiev Stage 14, Grand Prix of Tatarstan, Sunday, April 2, 2017 Problem L. Canonical duel的更多相关文章

  1. 【二分】【字符串哈希】【二分图最大匹配】【最大流】XVII Open Cup named after E.V. Pankratiev Stage 14, Grand Prix of Tatarstan, Sunday, April 2, 2017 Problem I. Minimum Prefix

    给你n个字符串,问你最小的长度的前缀,使得每个字符串任意循环滑动之后,这些前缀都两两不同. 二分答案mid之后,将每个字符串长度为mid的循环子串都哈希出来,相当于对每个字符串,找一个与其他字符串所选 ...

  2. XVII Open Cup named after E.V. Pankratiev Stage 14, Grand Prix of Tatarstan, Sunday, April 2, 2017 Problem A. Arithmetic Derivative

    题目:Problem A. Arithmetic DerivativeInput file: standard inputOutput file: standard inputTime limit: ...

  3. XVII Open Cup named after E.V. Pankratiev Stage 14, Grand Prix of Tatarstan, Sunday, April 2, 2017 Problem D. Clones and Treasures

    题目:Problem D. Clones and TreasuresInput file: standard inputOutput file: standard outputTime limit: ...

  4. 【动态规划】【滚动数组】【bitset】XVII Open Cup named after E.V. Pankratiev Stage 14, Grand Prix of Tatarstan, Sunday, April 2, 2017 Problem J. Terminal

    有两辆车,容量都为K,有n(10w)个人被划分成m(2k)组,依次上车,每个人上车花一秒.每一组的人都要上同一辆车,一辆车的等待时间是其停留时间*其载的人数,问最小的两辆车的总等待时间. 是f(i,j ...

  5. 【枚举】【最小表示法】XVII Open Cup named after E.V. Pankratiev Stage 14, Grand Prix of Tatarstan, Sunday, April 2, 2017 Problem F. Matrix Game

    给你一个n*m的字符矩阵,将横向(或纵向)全部裂开,然后以任意顺序首尾相接,然后再从中间任意位置切开,问你能构成的字典序最大的字符串. 以横向切开为例,纵向类似. 将所有横排从大到小排序,枚举最后切开 ...

  6. 【推导】【构造】XVII Open Cup named after E.V. Pankratiev Stage 14, Grand Prix of Tatarstan, Sunday, April 2, 2017 Problem E. Space Tourists

    给你n,K,问你要选出最少几个长度为2的K进制数,才能让所有的n位K进制数删除n-2个元素后,所剩余的长度为2的子序列至少有一个是你所选定的. 如果n>K,那么根据抽屉原理,对于所有n位K进制数 ...

  7. 【推导】【贪心】XVII Open Cup named after E.V. Pankratiev Stage 14, Grand Prix of Tatarstan, Sunday, April 2, 2017 Problem D. Clones and Treasures

    给你一行房间,有的是隐身药水,有的是守卫,有的是金币. 你可以任选起点,向右走,每经过一个药水或金币就拿走,每经过一个守卫必须消耗1个药水,问你最多得几个金币. 药水看成左括号,守卫看成右括号, 就从 ...

  8. 【找规律】【DFS】XVII Open Cup named after E.V. Pankratiev Stage 14, Grand Prix of Tatarstan, Sunday, April 2, 2017 Problem A. Arithmetic Derivative

    假设一个数有n个质因子a1,a2,..,an,那么n'=Σ(a1*a2*...*an)/ai. 打个表出来,发现一个数x,如果x'=Kx,那么x一定由K个“基础因子”组成. 这些基础因子是2^2,3^ ...

  9. XVII Open Cup named after E.V. Pankratiev Stage 14, Grand Prix of Tatarstan, Sunday, April 2, 2017 Problem L. Canonical duel

    题目:Problem L. Canonical duelInput file: standard inputOutput file: standard outputTime limit: 2 seco ...

随机推荐

  1. this指针再解

     this.new.call和apply的相关问题 讲解this指针的原理是个很复杂的问题,如果我们从javascript里this的实现机制来说明this,很多朋友可能会越来越糊涂,因此本篇打算换一 ...

  2. socket 编程 TCP 实现简单聊天功能【转】

    转自:http://blog.csdn.net/liujia2100/article/details/9006479 版权声明:本文为博主原创文章,未经博主允许不得转载. 各个主要函数的功能: .so ...

  3. 学习 Linux,101: 自定义或编写简单脚本【转】

    转自:http://www.ibm.com/developerworks/cn/linux/l-lpic1-105-2/index.html 学习如何使用标准的 shell 语法.循环和控制结构,以及 ...

  4. 浅谈linux的死锁检测 【转】

    转自:http://www.blog.chinaunix.net/uid-25942458-id-3823545.html 死锁:就是多个进程(≥2)因为争夺资源而相互等待的一种现象,若无外力推动,将 ...

  5. sicily 1172. Queens, Knights and Pawns

    Description You all are familiar with the famous 8-queens problem which asks you to place 8 queens o ...

  6. C后端设计开发 - 第5章-内功-数据结构下卷

    正文 第5章-内功-数据结构下卷 后记 如果有错误, 欢迎指正. 有好的补充, 和疑问欢迎交流, 一块提高. 在此谢谢大家了.

  7. mysql utf8改utf8mb4

    由于需要用到utf8mb4,之前是utf8现在给改成utf8mb4 查看当前环境 SHOW VARIABLES WHERE Variable_name LIKE 'character\_set\_%' ...

  8. 安装sysstat出现软件包依赖问题

    需要使用Linux性能分析工具iostat 和sar等, 这就需要安装软件包sysstat 在Ubuntu 12.04下运行sudo apt-get install sysstat,出现如下问题: 开 ...

  9. windows下使用github

    1.首先到github.com注册用户: 2.下载git,地址:http://pan.baidu.com/s/1skPpWlB(64位下载):http://pan.baidu.com/s/1skOAa ...

  10. LeetCode解题报告—— Combination Sum & Combination Sum II & Multiply Strings

    1. Combination Sum Given a set of candidate numbers (C) (without duplicates) and a target number (T) ...