博客
关于我
B. Monopole Magnets(思维+连通块)
阅读量:264 次
发布时间:2019-03-01

本文共 1210 字,大约阅读时间需要 4 分钟。


思路:开始看成了白块区域不能放S极了。

看懂题意的话还是能做对的。

1.如果有一行/一列存在不连续的黑块。 -1

2.如果有一行全空而不存在列全空。-1/反之亦然。

剩下的就全部扔S极,每个连通块里扔一个N极就好

#include
#include
#include
#include
#include
#include
#include
#include
#include
#define debug(a) cout<<#a<<"="<
<
>n>>m; for(LL i=0;i
>ma[i][j]; } } bool flag=1; bool r1=false; bool l1=false; for(LL i=1;i<=n;i++){ LL num=0; for(LL j=1;j<=m;j++){ if(num==0&&ma[i][j]=='#') num=1; else if(num==1&&ma[i][j]=='.') num=2; else if(num==2&&ma[i][j]=='#'){ flag=0;break; } } if(num==0) r1=true; } for(LL j=1;j<=m;j++){ LL num=0; for(LL i=1;i<=n;i++){ if(num==0&&ma[i][j]=='#') num=1; else if(num==1&&ma[i][j]=='.') num=2; else if(num==2&&ma[i][j]=='#'){ flag=0;break; } } if(num==0) l1=true; } if(r1!=l1) flag=0; if(flag==0){ cout<<"-1"<<"\n"; } else{ for(LL i=1;i<=n;i++){ for(LL j=1;j<=m;j++){ if(ma[i][j]!='#') continue; for(LL k=0;k<4;k++){ LL nx=i+dx[k];LL ny=j+dy[k]; if(nx<1||ny<1||nx>n||ny>m) continue; if(ma[nx][ny]=='#'&&find(get(nx,ny))!=find(get(i,j))){ fa[find(get(nx,ny))]=find(get(i,j)); } } } } LL ans=0; for(LL i=1;i<=n;i++){ for(LL j=1;j<=m;j++){ if(ma[i][j]=='#'&&fa[get(i,j)]==get(i,j)){ ans++; } } } cout<
<<"\n"; } return 0;}

 

转载地址:http://vact.baihongyu.com/

你可能感兴趣的文章
Mtab书签导航程序 LinkStore/getIcon SQL注入漏洞复现
查看>>
myeclipse配置springmvc教程
查看>>
MyEclipse配置SVN
查看>>
MTCNN 人脸检测
查看>>
MyEcplise中SpringBoot怎样定制启动banner?
查看>>
MyPython
查看>>
MTD技术介绍
查看>>
MySQL
查看>>
MySQL
查看>>
mysql
查看>>
MTK Android 如何获取系统权限
查看>>
MySQL - 4种基本索引、聚簇索引和非聚索引、索引失效情况、SQL 优化
查看>>
MySQL - ERROR 1406
查看>>
mysql - 视图
查看>>
MySQL - 解读MySQL事务与锁机制
查看>>
MTTR、MTBF、MTTF的大白话理解
查看>>
mt_rand
查看>>
mysql -存储过程
查看>>
mysql /*! 50100 ... */ 条件编译
查看>>
mudbox卸载/完美解决安装失败/如何彻底卸载清除干净mudbox各种残留注册表和文件的方法...
查看>>