主题链接:点击打开链接

意甲冠军:特定n*m矩阵

X代表色 .代表无色

随着x*y形刷子去涂色。

刷子每次能够→或↓移动随意步。

若可以染出给定的矩阵,则输出最小的刷子的面积

若不能输出-1

思路:

先找到连续最小的x,y

由于至少一个边界和x或y相等,所以枚举(x,i) 和 (i,y)就能够了。

#pragma comment(linker, "/STACK:102400000,102400000")
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string.h>
using namespace std;
#define N 1010
int top;
char s[N][N];
int n, m, stx, sty;
int H(int h, int l, int r){//扫一行 -1表示全是. 1表示全是X 0表示都有if(h>n || r>m) return -2;int cnt = 0;for(int i = l; i <= r; i++)if(s[h][i]=='X')cnt++;if(cnt==0)return -1;if(cnt==r-l+1)return 1;return 0;
}
int L(int l, int S, int X){if(l>m || X>n) return -2;int cnt = 0;for(int i = S; i <= X; i++)if(s[i][l]=='X')cnt++;if(cnt==0)return -1;if(cnt==X-S+1)return 1;return 0;
}
bool ok(int x, int y){//  printf(" ++++++(%d,%d)\n", x,y);int nowx = stx, nowy = sty;if(nowx + x-1 > n || nowy + y-1>m)return false;for(int i = 0; i < x; i++)for(int j = 0; j < y; j++)if(s[i+nowx][j+nowy]!='X')return false;//   puts("---");put(); puts("-----");int cnt = x*y;while(1){if(nowx + x <= n && s[nowx+x][nowy] =='X'){nowx ++;for(int i = 0; i < y; i++)if(s[nowx+x-1][i+nowy]!='X')return false;cnt += y;}else if(nowy + y <= m && s[nowx][nowy+y] == 'X'){nowy++;for(int i = 0; i < x; i++)if(s[i+nowx][nowy+y-1]!='X')return false;cnt += x;}else break;//    puts("******");put();}return cnt == top;
}
int hehe; int feifei;
int x, y;
void find_xy(){x = N, y = N;for(int i = 1; i <= m; i++) {int cnt = 0;for(int j = 1; j <= n; j++){if(s[j][i]=='.'){if(cnt) x = min(x, cnt);cnt = 0;}elsecnt++;}if(cnt) x = min(x, cnt);}for(int i = 1; i <= n; i++) {int cnt = 0;for(int j = 1; j <= m; j++){if(s[i][j]=='.'){if(cnt) y = min(y, cnt);cnt = 0;}else cnt++;}if(cnt) y = min(y, cnt);}
}
int solve(){int ans = N*N;for(int i = 1; i <= x; i++)if(ok(i,y)) {ans = i*y;break;}for(int i = 1; i <= y && x*i<ans; i++)if(ok(x,i)){ans = x*i;break;}if(ans > n*m) return -1;return ans;
}
void input(){stx = -1;top = 0;for(int i = 1; i <= n; i++){scanf("%s", s[i]+1);for(int j = 1; j <= m; j++) {if(stx==-1 && s[i][j]=='X'){stx = i, sty = j;}top += s[i][j]=='X';}}
}
int main(){while(cin>>n>>m){input();find_xy();printf("%d\n", solve());}return 0;
}

版权声明:本文博主原创文章,博客,未经同意不得转载。

转载于:https://www.cnblogs.com/hrhguanli/p/4823623.html

Codeforces 475C Kamal-ol-molk#39;s Painting 模拟相关推荐

  1. CodeForces - 1245A Good ol' Numbers Coloring (思维)

    Codeforces Round #597 (Div. 2 Consider the set of all nonnegative integers: 0,1,2,-. Given two integ ...

  2. Codeforces Round #700 (Div. 2) D1 D2. Painting the Array 思维

    link 题意: 给一个数组,让你从头开始选出一些数放在AAA数组中,剩下的放在BBB数组中,且是有序选择,让后把两个数组中相邻且相等的元素合并. D1: 使合并后Len(A)+Len(B)Len(A ...

  3. Codeforces Round #441 D. Sorting the Coins(模拟)

    http://codeforces.com/contest/876/problem/D 题意: 题意真是难懂,就是给一串序列,第i次操作会在p[x](1<=x<=i)这些位置放上硬币,然后 ...

  4. Codeforces Round #325 (Div. 2) Laurenty and Shop 模拟

    原题链接:http://codeforces.com/contest/586/problem/B 题意: 大概就是给你一个两行的路,让你寻找一个来回的最短路,并且不能走重复的路. 题解: 就枚举上下选 ...

  5. Educational Codeforces Round 96 E. String Reversa 线段树模拟序列交换

    传送门 文章目录 题意: 思路: 题意: 思路: 与上一篇题解大同小异,无非就是不需要枚举排列了. // Problem: E. String Reversal // Contest: Codefor ...

  6. Codeforces 439C Devu and Partitioning of the Array(模拟)

    题目链接:Codeforces 439C Devu and Partitioning of the Array 题目大意:给出n个数,要分成k份,每份有若干个数,可是仅仅须要关注该份的和为奇数还是偶数 ...

  7. Codeforces Round #180 (Div. 2) B. Sail 【模拟】

    B. Sail time limit per test 1 second memory limit per test 256 megabytes input standard input output ...

  8. CodeForces - 916D Jamie and To-do List(主席树+模拟)

    题目链接:点击查看 题目大意:模拟实现 nnn 次操作,每次操作共有四种类型: setaixiset \ a_i \ x_iset ai​ xi​:设置 aia_iai​ 的优先级为 xix_ixi​ ...

  9. CodeForces - 504B Misha and Permutations Summation(线段树模拟康托展开与逆展开)

    题目链接:点击查看 题目大意:给出两个排列 ppp 和 qqq,现在要求输出 Perm((Ord(p)+Ord(q))modn!)Perm((Ord(p)+Ord(q)) \bmod n!) Perm ...

  10. CodeForces - 820D Mister B and PR Shifts(思维+模拟)

    题目链接:点击查看 题目大意:给出一个长度为 n 的排列 p,可以执行数次循环右移的操作,问的最小值是多少 题目分析:暴力的话用 n * n 很容易实现 ,但数据是 1e6 的,显然又不能用暴力去写, ...

最新文章

  1. 6 Java Shell排序
  2. 关于学习Python的一点学习总结(56->random的使用)
  3. Facebook Auth API文档中没说清楚的事情 (2011-02-28更新)
  4. Centos7 下部署PPTP
  5. php tongjiapi 使用_Kayako REST API使用详解一
  6. c++备忘录模式mememto
  7. #ifndef #define #endif ”防止头文件被重复包 .
  8. scope python_Python标准库Scope
  9. 移植ubuntu14.04根文件系统至beaglebone开发板探索
  10. chrome的cookies
  11. 220万电商人竞相参与,阿里巴巴认证解决企业人才难题
  12. php友情链接代码,php友情链接
  13. Programming Languages PartB Week1学习笔记——Racket纯函数式编程语言
  14. 6.13编一程序,将两个字符串连接起来,不要用strcat函数。
  15. vs2010+opencv2.4.9配置========重点说明
  16. iPhone的快捷键
  17. ffmpeg转码过程分析
  18. 基于Wireshark的IP数据包头中ToS段介绍2-1
  19. 微信公众号测试账号网址
  20. 2019.8.设计菜单,完成简单计算器功能。要求:设计5个菜单项,功能分别为加减乘除。

热门文章

  1. 【转】Android bluetooth介绍(三): 蓝牙扫描(scan)设备分析
  2. java开发_eclipse导出为war文件,热部署到tomcat运行总结[转]
  3. LINUX邮件服务器
  4. vue开发环境的搭建流程
  5. 解决跨域form表单post提交时Forbidden的问题。
  6. 【例7.4】 循环比赛日程表
  7. linux的jdk、tomcat、tomcat安装等
  8. Knockout v3.4.0 中文版教程-6-计算监控-可写的计算监控
  9. 虚继承 - C++快速入门29
  10. MOSFET(一):基础