题目:Problem L. Canonical duel
Input file: standard input
Output file: standard output
Time limit: 2 seconds
Memory limit: 256 megabytes
In the game «Canonical duel» board N × M is used. Some of the cells of the board contain turrets. A
turret is the unit with four cannons oriented to north, east, south and west. Each turret can shoot exactly
once. When turret is hit by the cannon of another turret, its activated. When turret is activated, all four
cannons shoot simultaneously, then self-destruction process causes the turret to disappear.
Given the board with some turrets. You may add exactly one turret on one of cells which does not
contains a turret and activate this new turret. Your goal is to destroy maximum number of turrets.
Input
First line of the input contains two positive integers N and M, does not exceeding 2000 — size of the
board.
Each of the next N lines contain exactly M chars: ‘+’ denotes that cell is occupied by a turret, and ‘.’
that cell is empty.
Output
In the first line print maximum number of existing turrets you may destroy, then in second line print two
space-separated integers — row and column of place where turret can be set. If it is impossible to destroy
ever one turret in such a way, print only one line containing a zero; if several solutions exist, print any of
them.
Examples

standard input standard output
3 4
++..
+...
..++
5
2 4
4 5
++...
..+..
....+
...++
5
4 1
3 3
+++
+++
+++
0

思路:

  用并查集维护每个点所能炸的点数量,然后处理出每个空位置上下左右最近的炮台的位置。之后枚举放置位置即可。

  

 #include <bits/stdc++.h>

 using namespace std;

 #define MP make_pair
#define PB push_back
typedef long long LL;
typedef pair<int,int> PII;
const double eps=1e-;
const double pi=acos(-1.0);
const int K=1e6+;
const int mod=1e9+; char ss[][];
int n,m,ans,ansx,ansy,f[],cnt[];
int dir[][],vis[];
int idx(int i,int j)
{
if(i<||j<||i>n||j>m) return ;
return (i-)*m+j;
}
int fd(int x)
{
return f[x]==x?x:f[x]=fd(f[x]);
}
void join(int y,int x)
{
int fx=fd(x),fy=fd(y);
if(fx!=fy)
f[fy]=fx,cnt[fx]+=cnt[fy];
}
int main(void)
{
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)
scanf("%s",&ss[i][]);
for(int i=;i<=n;i++)
for(int j=;j<=m;j++)
f[idx(i,j)]=idx(i,j),cnt[idx(i,j)]=ss[i][j]=='+';
for(int i=;i<=n;i++)
for(int j=;j<=m;j++)
{
dir[idx(i,j)][]=ss[i-][j]=='+'?idx(i-,j):dir[idx(i-,j)][];
dir[idx(i,j)][]=ss[i][j-]=='+'?idx(i,j-):dir[idx(i,j-)][];
}
for(int i=n;i;i--)
for(int j=m;j;j--)
{
dir[idx(i,j)][]=ss[i+][j]=='+'?idx(i+,j):dir[idx(i+,j)][];
dir[idx(i,j)][]=ss[i][j+]=='+'?idx(i,j+):dir[idx(i,j+)][];
}
for(int i=;i<=n;i++)
for(int j=;j<=m;j++)
if(ss[i][j]=='+')
{
if(dir[idx(i,j)][]) join(idx(i,j),dir[idx(i,j)][]);
if(dir[idx(i,j)][]) join(idx(i,j),dir[idx(i,j)][]);
//printf("f[%d][%d]:%d\n",i,j,f[idx(i,j)]);
}
// for(int i=1;i<=n;i++)
// for(int j=1;j<=m;j++)
// {
// printf("dir[%d][%d]:",i,j);
// for(int k=1;k<=4;k++)
// printf("%d ",dir[idx(i,j)][k]);
// printf("\n");
// }
// for(int i=1;i<=n;i++)
// for(int j=1;j<=m;j++)
// if(f[idx(i,j)]==idx(i,j))
// printf("cnt[%d][%d]:%d\n",i,j,cnt[idx(i,j)]);
for(int i=;i<=n;i++)
for(int j=;j<=m;j++)
if(ss[i][j]=='.')
{
int sum=;
for(int k=;k<=;k++)
if(!vis[fd(dir[idx(i,j)][k])])
vis[fd(dir[idx(i,j)][k])]=,sum+=cnt[fd(dir[idx(i,j)][k])];
for(int k=;k<=;k++)
vis[fd(dir[idx(i,j)][k])]=;
//printf("sum:%d %d %d\n",i,j,sum);
if(sum>ans)
ans=sum,ansx=i,ansy=j;
}
if(ans) printf("%d\n%d %d\n",ans,ansx,ansy);
else printf("0\n");
return ;
}

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 F. Matrix Game

    题目: Problem F. Matrix GameInput file: standard inputOutput file: standard inputTime limit: 1 secondM ...

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

    题目:Problem J. TerminalInput file: standard inputOutput file: standard inputTime limit: 2 secondsMemo ...

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

  4. 【二分】【字符串哈希】【二分图最大匹配】【最大流】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的循环子串都哈希出来,相当于对每个字符串,找一个与其他字符串所选 ...

  5. 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: ...

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

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

  7. 【动态规划】【滚动数组】【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 ...

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

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

  9. 【推导】【构造】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进制数 ...

随机推荐

  1. WTL:下载、安装、初见

    简介 WTL: Windows Template Library 基于ATL对Win32 API的封装 C++库,用于开发Windows应用程序和UI组件 WTL功能不如MFC完善,但比MFC更小巧更 ...

  2. VS2008 对话框编辑器“即时预览”

    之前在VS2008中利用资源编辑器修改完对话框资源后,总是重新编译一下,然后Ctrl+F5运行来预览修改的效果,不断修改,不断编译,导致很费时,效率低下. 今天,发现了一个很好用的功能“Test Di ...

  3. 用原生Canvas写贪吃蛇及问题解决

    为了学习Canvas,写了这个小游戏贪吃蛇供自己和大家学习 Github: https://github.com/zhiyishou/Gsnake Play On: http://zhiyishou. ...

  4. Angular 组件与模板 - 属性指令

    指令概览 在 Angular 中有三种类型的指令: 组件 — 拥有模板的指令 结构型指令 — 通过添加和移除 DOM 元素改变 DOM 布局的指令 属性型指令 — 改变元素.组件或其它指令的外观和行为 ...

  5. JQuery------实现鼠标摁下抬起时div背景色改变

    作用:使用自定义一个按钮 代码: <div class = 'btn'>按钮</div> $(".btn").mousedown(function () { ...

  6. iOS开发之--MVC 架构模式

    随着项目开发时间的增加,从刚开始那种很随意的代码风格,逐渐会改变,现在就介绍下MVC的架构模式,MVC的架构模式,从字面意思上讲,即:MVC 即 Modal View Controller(模型 视图 ...

  7. python学习【第一篇】python介绍

    python发展历史 起源 Python的作者,Guido von Rossum,荷兰人.1982年,Guido从阿姆斯特丹大学获得了数学和计算机硕士学位.然而,尽管他算得上是一位数学家,但他更加享受 ...

  8. android studio升级时提示 Connection failed. Please check your network connection and try again

    原文地址 http://www.eyeapk.com/android-studio-update.html Mac OSX中修改文件路径为 bin/idea.vmoptions ,添加如下内容,如果无 ...

  9. Android 调用系统相机拍照保存以及调用系统相册的方法

    系统已经有的东西,如果我们没有新的需求的话,直接调用是最直接的.下面讲讲调用系统相机拍照并保存图片和如何调用系统相册的方法. 首先看看调用系统相机的核心方法: Intent camera = new ...

  10. js 中导出excel 较长数字串会变成科学计数法(转载)

    在做项目中,碰到如题的问题.比如要将居民的信息导出到excel中,居民的身份证号码因为长度过长(大于10位),excel会自动的将过长的数字串转换成 科学计数法.现在网上找到解决方案之一: (在数字串 ...