【CS Round #44 (Div. 2 only) B】Square Cover
【链接】点击打开链接
【题意】
【题解】
【错的次数】
【反思】
【代码】
/* */
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <cstdlib>
#include <cmath>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb emplace_back
#define fi first
#define se second
#define ld long double
#define ms(x,y) memset(x,y,sizeof x)
#define ri(x) scanf("%d",&x)
#define rl(x) scanf("%lld",&x)
#define rs(x) scanf("%s",x)
#define rf(x) scnaf("%lf",&x)
#define oi(x) printf("%d",x)
#define ol(x) printf("%lld",x)
#define oc putchar(' ')
#define os(x) printf(x)
#define all(x) x.begin(),x.end()
#define Open() freopen("F:\\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0)
#define sz(x) ((int) x.size())
#define ld long double typedef pair<int, int> pii;
typedef pair<LL, LL> pll; //mt19937 myrand(time(0));
//int get_rand(int n){return myrand()%n + 1;}
const int dx[9] = { 0,1,-1,0,0,-1,-1,1,1 };
const int dy[9] = { 0,0,0,-1,1,-1,1,-1,1 };
const double pi = acos(-1.0);
const int N = 3e2;
const int INF = 1e5; struct abc {
int x, y;
}; int n, m, a[N + 10][N + 10], maxx, minx, maxy, miny, cnt;
bool bo[N + 10][N + 10], flag[INF + 10];
queue <abc> dl; int main() {
//Open();
//Close();
ri(n), ri(m);
rep1(i, 1, n)
rep1(j, 1, m)
ri(a[i][j]);
rep1(i, 1, n)
rep1(j, 1, m)
if (!bo[i][j]) {
if (flag[a[i][j]])
return puts("0"), 0;
flag[a[i][j]] = true;
cnt = 1;
maxx = minx = i, maxy = miny = j;
abc temp;
temp.x = i, temp.y = j;
dl.push(temp);
bo[i][j] = true;
while (!dl.empty()) {
int x = dl.front().x, y = dl.front().y;
dl.pop();
rep1(k, 1, 4) {
int tx = x + dx[k], ty = y + dy[k];
if (tx >= 1 && tx <= n && ty >= 1 && ty <= m) {
if (!bo[tx][ty] && a[tx][ty] == a[i][j]) {
bo[tx][ty] = true;
minx = min(minx, tx), maxx = max(maxx, tx);
miny = min(miny, ty), maxy = max(maxy, ty);
cnt++;
temp.x = tx, temp.y = ty;
dl.push(temp);
}
}
}
}
if (cnt != (maxx - minx+1)*(maxx - minx+1))
return puts("0"), 0;
}
puts("1");
return 0;
}
【CS Round #44 (Div. 2 only) B】Square Cover的更多相关文章
- 【CS Round #44 (Div. 2 only) D】Count Squares
[链接]点击打开链接 [题意] 给你一个0..n和0..m的区域. 你可以选定其中的4个点,然后组成一个正方形. 问你可以圈出多少个正方形. (正方形的边不一定和坐标轴平行) [题解] 首先,考虑只和 ...
- 【CS Round #44 (Div. 2 only) A】Frequent Numbers
[链接]h在这里写链接 [题意] 在这里写题意 [题解] 大水题 [错的次数] 0 [反思] 在这了写反思 [代码] /* */ #include <cstdio> #include &l ...
- 【CS Round #44 (Div. 2 only) C】Check DFS
[链接]点击打开链接 [题意] 给你一个n节点,m条边的无向联通图. 给你一个节点访问的顺序.(1..n的排列) 你可以改变每个点优先访问的出度.(但必须按照dfs的规则); 问你能不能按照所给的访问 ...
- 【CS Round #36 (Div. 2 only) A】Bicycle Rental
[题目链接]:https://csacademy.com/contest/round-36/task/bicycle-rental/ [题意] 让你从n辆车中选一辆车; 每一辆车有3个属性 1.到达车 ...
- 【CS Round #37 (Div. 2 only) D】Reconstruct Graph
[Link]:https://csacademy.com/contest/round-37/task/reconstruct-graph/statement/ [Description] 给你一张图; ...
- 【CS Round #37 (Div. 2 only) B】Group Split
[Link]:https://csacademy.com/contest/round-37/task/group-split/ [Description] 让你把一个数分成两个数a.b的和; (a,b ...
- 【CS Round #37 (Div. 2 only) A】Boring Number
[Link]:https://csacademy.com/contest/round-37/task/boring-number/ [Description] 让你找离平均数最近的一个数的下标; [S ...
- 【CS Round #39 (Div. 2 only) D】Seven-segment Display
[Link]:https://csacademy.com/contest/round-39/task/seven-segment-display/ [Description] 0..9各自有一个数字, ...
- 【CS Round #39 (Div. 2 only) C】Reconstruct Sum
[Link]:https://csacademy.com/contest/round-39/task/reconstruct-sum/ [Description] 给你一个数字S; 让你找有多少对A, ...
随机推荐
- Tree and Permutation (HDU 6446) 题解
// 昨天打了一场网络赛,表现特别不好,当然题目难度确实影响了发挥,但还是说明自己太菜了,以后还要多多刷题. 2018 CCPC 网络赛 I - Tree and Permutation 简单说明一下 ...
- 凉凉了,Eureka 2.x 停止维护,Spring Cloud 何去何从?
今年 Dubbo 活了,并且被 Apache 收了.同时很不幸,Spring Cloud 下的 Netflix Eureka 组件项目居然宣布停止开发了.. 已经从 Dubbo 迁移至 Spring ...
- python 编码问题:'ascii' codec can't encode characters in position 的解决方案
报错: 'ascii' codec can't encode characters in position 8-50: ordinal not in range(128) Python在安装时,默认的 ...
- 2018-12-17-VisualStudio-使用新项目格式快速打出-Nuget-包
title author date CreateTime categories VisualStudio 使用新项目格式快速打出 Nuget 包 lindexi 2018-12-17 14:11:50 ...
- 分批次删除大表数据的shell脚本
#!/bin/bash # 分别是主机名,端口,用户,密码,数据库,表名称,字段名称 readonly HOST="XXX" readonly PORT=" readon ...
- 安装postgresql11.5
root身份安装 创建用户 编译安装成功后,接下来要做的就是创建一个普通用户,因为默认超级用户(root)不能启动postgresql,所以需要创建一个普通用户来启动数据库,执行以下命令创建用户: [ ...
- MyBatis-Spring(四)--MapperFactoryBean实现增删改查
上一篇文章中提到,使用SqlSessionTemplat时需要输入一长串字符串来获取mapper,这种方式IDE不会检查程序的准确性并且很容易出错,所以这篇文章介绍另一种可以避免这种问题,并且也可以使 ...
- 处理iphone的 .play() 不能播放问题
一.添加音乐 <audio id="Jaudio" src="shake.mp3" preload loop="loop" contr ...
- PHP中的符号 ->、=> 和 :: 的含义(用法)
php新手经常碰到的问题,->.=> 和 :: 这三个家伙是什么分别都是做什么的啊!看着就很晕. 没关系,下面我们做一下详细的解释,如果你有C++,Perl基础,你会发现这些家伙和他们里面 ...
- mysql利用MySQLWorkbench生成数据表之间的关系图
先看结果,默认是展开的,我手动把表折叠了 那么如何实现呢 先点击这里 然后通过向导来创建即可,一直到finish就行了