Codeforces 1345 D - Monopole Magnets
这一场也是很神奇了,先是推迟三天,后是评测鸡崩了,unrated...
题意:每一行,每一列必须都要至少有一个s,n要可以到所有的黑格,n的上下左右如果有一个s,他就可以往那个方向移动一格,n最后不能在白格,求n最少的个数。
题解:
1、每一行每一列如果有#,#必须是连续的,否则输出-1
2、如果有一行没有#,那么至少有一列要没有#,s就可以放在交点处,否则输出-1。
3、求解连通块的个数
1 #include<bits/stdc++.h>
2 #define ll long long
3 using namespace std;
4
5 char a[1010][1010];
6 bool x[1010],y[1010]; //x记录有#的行,y记录有#的列
7 int dx[]={1,-1,0,0};
8 int dy[]={0,0,1,-1};
9
10 void dfs(int xx,int yy)
11 {
12 a[xx][yy]='.';
13 for(int i=0;i<4;i++){
14 int xxx=xx+dx[i];
15 int yyy=yy+dy[i];
16 if(a[xxx][yyy]=='#') dfs(xxx,yyy);
17 }
18 return ;
19 }
20
21 int main()
22 {
23 ios::sync_with_stdio(false);
24 cin.tie(0);
25 cout.tie(0);
26 int n,m;
27 cin>>n>>m;
28 for(int i=0;i<n;i++) cin>>a[i];
29 int flag=1;
30 for(int i=0;i<n;i++){
31 for(int j=0;j<m;j++){
32 if(a[i][j]=='#') {
33 if(x[i]&&j&&a[i][j-1]!='#'){
34 flag=0;
35 break;
36 }
37 if(y[j]&&i&&a[i-1][j]!='#'){
38 flag=0;
39 break;
40 }
41 x[i]=1,y[j]=1;
42 }
43 }
44 if(!flag) break;
45 }
46 int p=0,q=0;
47 for(int i=0;i<n;i++) if(!x[i]) p=1;
48 for(int i=0;i<m;i++) if(!y[i]) q=1;
49 if(p^q) flag=0; //如果有行没有# 而没有列没有#或者反过来,就输出-1.
50 if(!flag) {cout<<-1<<endl;return 0;}
51 int ans=0;
52 for(int i=0;i<n;i++){
53 for(int j=0;j<m;j++){
54 if(a[i][j]=='#') ans++,dfs(i,j); //简单的找连通块
55 }
56 }
57 cout<<ans<<endl;
58 return 0;
59 }
Codeforces 1345 D - Monopole Magnets的更多相关文章
- Codeforces Round #330 (Div. 1) C. Edo and Magnets 暴力
C. Edo and Magnets Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/594/pr ...
- CodeForces - 344A Magnets (模拟题)
CodeForces - 344A id=46664" style="color:blue; text-decoration:none">Magnets Time ...
- codeforces Magnets
link:http://codeforces.com/contest/344/problem/A 这道题目很简单. 把输入的01 和10 当做整数,如果相邻两个数字相等的话,那么就属于同一组,否则,就 ...
- Codeforces 344A Magnets
Description Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dom ...
- coderforces Gym 100803A/Aizu 1345/CSU 1536/UVALive 6832 Bit String Reordering(贪心证明缺)
Portal: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1345 http://codeforces.com/gym/100 ...
- Codeforces Round #639 (Div. 2)
Codeforces Round #639 (Div. 2) (这场官方搞事,唉,just solve for fun...) A找规律 给定n*m个拼图块,每个拼图块三凸一凹,问能不能拼成 n * ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
随机推荐
- 如何使用 VS Code开发.NET Core应用程序
Visual Studio Code(VS Code)是Microsoft为Windows,Linux和Mac操作系统开发的免费,跨平台,轻量级的源代码编辑器,它是源代码编辑器,而Visual Stu ...
- 按装parallels tool的失败之路
这是一篇对于其他人来说没什么意义的博客.单纯的可以被看作是日记. 首先,我想安装parallels tool. 但是照着网上很多教程(如www.cnblogs.com/artwalker/p/1323 ...
- kubernetes 核心技术-Controller 控制器
一.什么是Controller? Controller是在集群上管理和运行容器的对象,Controller是实际存在的,Pod是抽象的,主要创建管理pod 二.Pod和Controller的关系 Po ...
- 导出exe的经验
安装pyinstaller 首先要找到scripts的绝对路径(主要是找到scripts就行了 先是安装C:\Users\96290\AppData\Local\Programs\Python\Pyt ...
- 相对论中的光速c不变,这么讲!你总能理解了吧!
今天谈谈相对论的假设基础--光速不变,很多人都知道爱因斯坦的相对论,也知道相对论的理论基础是光速不变,即无论参考哪个参照系,光的速度都是不变的,这个很难得理解的问题.我之前看过别人的理解,也自己思考怎 ...
- C++中输出变量类型的方法
C++中输出变量类型的方法 在c++中输出变量或者数据类型,使用typeid().name()的方法.如下例子: #include <iostream> #include <stri ...
- C#高级编程第11版 - 第六章 索引
[1]6.2 运算符 1.&符在C#里是逻辑与运算.管道符号|在C#里则是逻辑或运算.%运算符用来返回除法运算的余数,因此当x=7时,x%5的值将是2. [2]6.2.1 运算符的简写 1.下 ...
- jQuery mock.js模拟的使用
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...
- jemeter断言和性能分析
一.添加断言 1.原因:检查是否有该结果,一般一个请求过去除了400和500的只要通过的都会代表请求成功,比如登录页面及时填写了错误密码,虽然会返回密码错误,但这个请求还是成功的,所以我们要添加断言, ...
- What is the difference between btree and rtree indexing?
https://softwareengineering.stackexchange.com/questions/113256/what-is-the-difference-between-btree- ...