CodeForces745B B - Hongcow Solves A Puzzle 暴力+判断
来源:互联网 发布:淘宝隐形眼镜可以买吗 编辑:程序博客网 时间:2024/05/21 09:48
Hongcow likes solving puzzles.
One day, Hongcow finds two identical puzzle pieces, with the instructions "make a rectangle" next to them. The pieces can be described by an n by m grid of characters, where the character 'X' denotes a part of the puzzle and '.' denotes an empty part of the grid. It is guaranteed that the puzzle pieces are one 4-connected piece. See the input format and samples for the exact details on how a jigsaw piece will be specified.
The puzzle pieces are very heavy, so Hongcow cannot rotate or flip the puzzle pieces. However, he is allowed to move them in any directions. The puzzle pieces also cannot overlap.
You are given as input the description of one of the pieces. Determine if it is possible to make a rectangle from two identical copies of the given input. The rectangle should be solid, i.e. there should be no empty holes inside it or on its border. Keep in mind that Hongcow is not allowed to flip or rotate pieces and they cannot overlap, i.e. no two 'X' from different pieces can share the same position.
The first line of input will contain two integers n and m (1 ≤ n, m ≤ 500), the dimensions of the puzzle piece.
The next n lines will describe the jigsaw piece. Each line will have length m and will consist of characters '.' and 'X' only. 'X' corresponds to a part of the puzzle piece, '.' is an empty space.
It is guaranteed there is at least one 'X' character in the input and that the 'X' characters form a 4-connected region.
Output "YES" if it is possible for Hongcow to make a rectangle. Output "NO" otherwise.
2 3XXXXXX
YES
2 2.XXX
NO
5 5.......X.................
YES
For the first sample, one example of a rectangle we can form is as follows
111222111222
For the second sample, it is impossible to put two of those pieces without rotating or flipping to form a rectangle.
In the third sample, we can shift the first tile by one to the right, and then compose the following rectangle:
.......XX................
判断是否为正方形
#include <iostream> #include <cstdio>#include <cstdlib>#include <cmath>#include <algorithm>#include <climits>#include <cstring>#include <string>#include <set>#include <map>#include <queue>#include <stack>#include <vector>#include <list>#define rep(i,m,n) for(i=m;i<=n;i++)#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)const int inf_int = 2e9;const long long inf_ll = 2e18;#define inf_add 0x3f3f3f3f#define mod 1000000007#define vi vector<int>#define pb push_back#define mp make_pair#define fi first#define se second#define pi acos(-1.0)#define pii pair<int,int>#define Lson L, mid, rt<<1#define Rson mid+1, R, rt<<1|1const int maxn=5e2+10;using namespace std;typedef long long ll;typedef unsigned long long ull; inline int read(){int ra,fh;char rx;rx=getchar(),ra=0,fh=1;while((rx<'0'||rx>'9')&&rx!='-')rx=getchar();if(rx=='-')fh=-1,rx=getchar();while(rx>='0'&&rx<='9')ra*=10,ra+=rx-48,rx=getchar();return ra*fh;}//#pragma comment(linker, "/STACK:102400000,102400000")ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}int mapp[505][505];bool judge(int x,int y,int ct);int n,m,ct;int main(){ios::sync_with_stdio(false); cin >> n>>m;int endx=-1,endy=-1;for(int i=0;i<n;i++){string s;cin >>s;for(int j=0;j<s.size();j++){if(s[j]=='.'){mapp[i][j] = 0; }else{mapp[i][j] = 1;endx = i;endy = j; ct++;}} }/*for(int i=0;i<n;i++){for(int j=0;j<m;j++){cout << mapp[i][j]<<" ";}cout <<endl;}*/if(endx==-1){cout << "NO"<<endl;}else{if(judge(endx,endy,ct)){cout << "YES"<<endl;}else{cout << "NO"<<endl;}} return 0; }bool judge(int x,int y,int ct){int lenx=0,leny=0;for(int i=x;i>=0;i--){if(mapp[i][y]==1)lenx++; elsebreak;} for(int i=y;i>=0;i--){if(mapp[x][i]==1)leny++; elsebreak;} if(ct!=lenx*leny){return false;}//cout << lenx <<":"<<leny<<endl;for(int i=x;i>=x-lenx+1;i--){for(int j=y;j>=y-leny+1;j--){if(mapp[i][j]==0)return false;} } return true;}
- CodeForces745B B - Hongcow Solves A Puzzle 暴力+判断
- Codeforce#385B.Hongcow Solves A Puzzle
- CodeForces 745B Hongcow Solves A Puzzle
- 745 B. Hongcow Solves A Puzzle codeforces
- 【Codeforces 745 B Hongcow Solves A Puzzle】
- Codeforces Round #385 (Div. 2)B. Hongcow Solves A Puzzle【思维+暴力】
- Codeforces Round #385 (Div. 2) -- B. Hongcow Solves A Puzzle (判断是否是矩形,水题)
- Hongcow Solves A Puzzle (思维)
- Hongcow Solves A Puzzle CodeForces
- 【37.50%】【codeforces 745B】Hongcow Solves A Puzzle
- Codeforces Round #385 (Div. 2) B. Hongcow Solves A Puzzle
- Codeforces Round #385 (Div. 2) B. Hongcow Solves A Puzzle 几何、思维题
- Codeforces Round #385 (Div. 2) 745B Hongcow Solves A Puzzle
- HDU1755 A Number Puzzle【全排列+暴力】
- Codeforces Round #385 (Div. 2)A.Hongcow Learns the Cyclic Shift【暴力】水题
- codeforces A. Orchestra B. Island Puzzle
- hdoj A Number Puzzle 1775 (暴力模拟)
- Hongcow Builds A Nation CodeForces
- Python使用tensorflow中梯度下降算法求解变量最优值
- Winform 窗体传值
- setlocal enabledelayedexpansion的作用
- Java工程通过JDBC连接数据库方法(SQL Server)
- 设计模式系列之十二状态模式
- CodeForces745B B - Hongcow Solves A Puzzle 暴力+判断
- Combination Sum
- Retrofit源码分析
- 3. Tomcat
- dos下 和 批处理中的 for 语句的基本用法
- iOS - Swift 自定义UITabBarController
- 文章标题
- 斐波那契数列-递归
- Windows下用breakpad抓取C++程序崩溃报告