Codeforces 475C Kamal-ol-molk's Painting 模拟
主题链接:点击打开链接
意甲冠军:特定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;
}
else
cnt++;
}
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;
}
版权声明:本文博主原创文章,博客,未经同意不得转载。
Codeforces 475C Kamal-ol-molk's Painting 模拟的更多相关文章
- codeforces 373 A - Efim and Strange Grade(算数模拟)
codeforces 373 A - Efim and Strange Grade(算数模拟) 原题:Efim and Strange Grade 题意:给出一个n位的实型数,你可以选择t次在任意位进 ...
- Codeforces Round #353 (Div. 2) B. Restoring Painting 水题
B. Restoring Painting 题目连接: http://www.codeforces.com/contest/675/problem/B Description Vasya works ...
- codeforces 459D - Pashmak and Parmida's problem【离散化+处理+逆序对】
题目:codeforces 459D - Pashmak and Parmida's problem 题意:给出n个数ai.然后定义f(l, r, x) 为ak = x,且l<=k<=r, ...
- Codeforce 475 C. Kamal-ol-molk's Painting
从最左上的点開始枚举长宽.... C. Kamal-ol-molk's Painting time limit per test 2 seconds memory limit per test 256 ...
- Codeforces Round #461 (Div. 2) C. Cave Painting
C. Cave Painting time limit per test 1 second memory limit per test 256 megabytes Problem Descriptio ...
- Codeforces Round #599 (Div. 1) A. Tile Painting 数论
C. Tile Painting Ujan has been lazy lately, but now has decided to bring his yard to good shape. Fir ...
- CodeForces - 1245A Good ol' Numbers Coloring (思维)
Codeforces Round #597 (Div. 2 Consider the set of all nonnegative integers: 0,1,2,-. Given two integ ...
- 爆搜 + 模拟 --- codeforces 475C
Problem's Link:http://codeforces.com/problemset/problem/475/Chttp://codeforces.com/problemset/proble ...
- Codeforces Round #313 C. Gerald's Hexagon(放三角形)
C. Gerald's Hexagon time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
随机推荐
- VC++学习之一
对于编程语言,我一直认为它只是一种工具,就像锤子,斧头一样,每种语言都用自己比较适用的地方,用的时候拿来就可以了.这种思想让我对语言没有做过很仔细的学习,虽然频繁使用过C,C++,java,C#,De ...
- 21副GIF动图让你了解各种数学概念(转。太强大了)
“让我们面对它:总的来说数学是不容易的,但当你征服了问题,并达到新的理解高度,这就是它给你的回报.” ——Danica McKellar 数学是很难的科学,但因为它是科学家用数学来解释宇宙的语言,我们 ...
- C语言运算符的优先级
熟悉C语言的同学都知道,C语言众多的运算符及繁琐难记的优先级总是搞得我们这些C初学者头大.那么本文就 对C语言中所有的运算符进行汇总,并对其优先级进行一定的介绍. 这里虽然对所有C运算符的优先级进行了 ...
- ios中strong, weak, assign, copy
copy 和 strong(retain) 区别 1. http://blog.csdn.net/itianyi/article/details/9018567 大部分的时候NSString的属性都是 ...
- ShareSDK QQ分享失败的坑
QQ分享的话,有标题和内容字符数限制,QQ好友的话限制的很小,标题30字符,内容40字符.分享之前限制一下.
- Exchange Cards(dfs)
Exchange Cards Time Limit: 2 Seconds Memory Limit: 65536 KB As a basketball fan, Mike is also f ...
- UVALive 6665 Dragonas Cruller
题目链接:https://icpcarchive.ecs.baylor.edu/external/66/6665.pdf 题目大意: 有一个3 * 3 的格子: 每个格子上面的数字能够朝上下左右四个方 ...
- To restore the database on a new host-将数据库恢复至一个新的主机上
To restore the database on a new host:1. Ensure that the backups of the target database are accessib ...
- JS 利用CNZZ进行站长统计
利用CNZZ对网站进行站长统计 前端页面只需要在body中添加如下代码即可: <script type="text/javascript">var cnzz_proto ...
- Android面试必备
好吧,说实话是自己面试被问到的和自己整理的别人的一些问题,很多问题的回答可能根据水平不同层次和深度不同,如果经常忘的话可能是还没明白原理,学习就是对对抗遗忘,现在开始复习吧: 每个面试的问题都极大的贴 ...