【链接】点击打开链接


【题意】


给你一个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;
}

最新文章

  1. Flex 布局教程:语法篇
  2. C语言 右左法则
  3. Post提交
  4. 理解 OpenStack + Ceph (1):Ceph + OpenStack 集群部署和配置
  5. jQuery 遍历(上)
  6. return, exit, _exit的区别
  7. TVM 下载监控
  8. 挂载NTFS
  9. Data Annotation
  10. Java设置环境变量
  11. 安装Cnario提示.Net 3.5安装错误, 检查Windows系统更新提示无法检查到更新, 安装.Net 3.5提示&quot;Windows无法完成请求的更改, 错误代码:0x800F081F&quot;
  12. JS面向对象之创建对象模式
  13. [Tensorflow] Cookbook - Object Classification based on CIFAR-10
  14. set_union和set_intersection
  15. PAT 乙级 1009 说反话 (20) C++版
  16. VisualSVN 破解方法
  17. 一次完整的HTTP接口请求过程及针对优化
  18. docker探索-docker容器基本操作(五)
  19. AndroidStudio 导包遇到so文件的解决方案----------JPush推送
  20. Mybatis笔记六:Mybatis中SqlSessionFactoryBuilder/SqlSessionFactory/SqlSession/映射器实例的作用域(Scope)和生命周期

热门文章

  1. 图片转成base64 跨域等安全限制及解决方案
  2. 左神算法进阶班4_2累加和为aim的最长子数组
  3. quartz任务调度基础: Job/Trigger/Schedule
  4. &lt;每日一题&gt;题目27:插入排序(假)
  5. Cat- Linux必学的60个命令
  6. 【核心核心】8.Spring【AOP】注解方式
  7. /etc/sysctl.conf配置文件
  8. Ubuntu下samba的安装和配置
  9. 解决微信浏览器内video全屏问题
  10. 逻辑备份(mysqldump/select into outfile)