【链接】点击打开链接


【题意】


给你一个n*m的矩形,让你在其中圈出若干个子正方形,使得这些子正方形里面的所有数字都是一样的.
且一样的数字,都是在同一个正方形里面。问你有没有方案。

【题解】


相同的必须在同一个子正方形里面.且正方形里面的数字都得是一样的。
那么只要每次找一个相同数字的连通块,然后看看这个连通块是不是一个正方形即可.
然后如果某个连通块出现了2次以上直接输出无解.(这两个数字不是连在一起的.中间肯定有其他数字)
如果某个连通块不是正方形,也直接输出无解。
(表示肯定会覆盖到其他的值,不是都一样的)

【错的次数】


0

【反思】


刚开始看的时候,觉得挺奇怪的一道题.
后来。。。后来还是觉得很奇怪。
那个子正方形里面"contain same values"我理解错了。。。
它是说里面的值全是一样的,而不是说里面“有一样的值”
耽误了好长时间.
这样想,相同的数字肯定都是聚在一个正方形里面的啦。

【代码】

/*

*/
#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的更多相关文章

  1. 【CS Round #44 (Div. 2 only) D】Count Squares

    [链接]点击打开链接 [题意] 给你一个0..n和0..m的区域. 你可以选定其中的4个点,然后组成一个正方形. 问你可以圈出多少个正方形. (正方形的边不一定和坐标轴平行) [题解] 首先,考虑只和 ...

  2. 【CS Round #44 (Div. 2 only) A】Frequent Numbers

    [链接]h在这里写链接 [题意] 在这里写题意 [题解] 大水题 [错的次数] 0 [反思] 在这了写反思 [代码] /* */ #include <cstdio> #include &l ...

  3. 【CS Round #44 (Div. 2 only) C】Check DFS

    [链接]点击打开链接 [题意] 给你一个n节点,m条边的无向联通图. 给你一个节点访问的顺序.(1..n的排列) 你可以改变每个点优先访问的出度.(但必须按照dfs的规则); 问你能不能按照所给的访问 ...

  4. 【CS Round #36 (Div. 2 only) A】Bicycle Rental

    [题目链接]:https://csacademy.com/contest/round-36/task/bicycle-rental/ [题意] 让你从n辆车中选一辆车; 每一辆车有3个属性 1.到达车 ...

  5. 【CS Round #37 (Div. 2 only) D】Reconstruct Graph

    [Link]:https://csacademy.com/contest/round-37/task/reconstruct-graph/statement/ [Description] 给你一张图; ...

  6. 【CS Round #37 (Div. 2 only) B】Group Split

    [Link]:https://csacademy.com/contest/round-37/task/group-split/ [Description] 让你把一个数分成两个数a.b的和; (a,b ...

  7. 【CS Round #37 (Div. 2 only) A】Boring Number

    [Link]:https://csacademy.com/contest/round-37/task/boring-number/ [Description] 让你找离平均数最近的一个数的下标; [S ...

  8. 【CS Round #39 (Div. 2 only) D】Seven-segment Display

    [Link]:https://csacademy.com/contest/round-39/task/seven-segment-display/ [Description] 0..9各自有一个数字, ...

  9. 【CS Round #39 (Div. 2 only) C】Reconstruct Sum

    [Link]:https://csacademy.com/contest/round-39/task/reconstruct-sum/ [Description] 给你一个数字S; 让你找有多少对A, ...

随机推荐

  1. Android之LinearLayout线性布局

    1.相关术语解释 orientation 子控件的排列方式,horizontal(水平)和vertical(垂直默认)两种方式! gravity 子控件的对齐方式,多个组合 layout_gravit ...

  2. sshfs实践记录

    sshfs是一款利器,可以将远程linux服务器的路径通过ssh协议挂载到本地指定路径.本地的文件一改动,就自动同步到远程服务器中. 本次的实验在centos 6.9中进行. 1.下载.安装所有的依赖 ...

  3. day 42 03--CSS布局设置

      03--CSS布局设置   本节目录 一 盒模型 二 padding(内边距) 三 boder(边框) 四 简单认识一下margin(外边距) 五 标准文档流 六 块级元素和行内元素 七 浮动 八 ...

  4. sip会话流程以及sip介绍(1)

    参考连接 :https://www.2cto.com/kf/201609/546336.html https://www.w3cschool.cn/session_initiation_protoco ...

  5. Redis学习笔记01-分布式锁

    1.分布式锁的定义与理解 在并发任务中,当对数据执行修改和删除时为了防止多个任务同时拿到数据而产生的混乱,这时就要用到分布式锁来限制程序的并发执行. Redis分布式锁本质上要实现的目标就是在Redi ...

  6. js 使用script或template标签:分离js代码template中的HTML元素

    参考:https://www.jianshu.com/p/332252abe016 方法一. script: <div id="app"> <com-first& ...

  7. Store工作原理

  8. [Swoole系列入门教程 6] TCP协议和粘包

  9. BZOJ 1933 [Shoi2007]Bookcase 书柜的尺寸

    神奇的dp优化. 考虑6维状态的dp,分别表示三行高和宽,显然MLE&&TLE. 把高排个序,从大到小往架上放,那么若不是重开一行便对高度没有影响. 然后求出宽度的sum,dp[i][ ...

  10. typescript使用小结

    1. typescript使得js在书写的过程中有了参数类型的限制在 传参的过程中变得严格,减少了不必要的错误的发生 2. tslint同时也兼备了一部分eslint的作用,在一定程度上我们使用tsl ...