UVALive 4867 Maximum Square 贪心
2015-01-21 10:32
459 查看
E - Maximum Square
Time Limit:4500MS Memory Limit:0KB 64bit IO Format:%lld & %llu
Submit Status Practice UVALive 4867
Description
Given an NxM matrix of all 1s and 0s, find the largest submatrix which is a square containing all 1s.
Input
There will be several test cases in the input. Each test case will begin with two integers, N and M(1
N, M
1, 000) indicating the number of rows and columns of the matrix. The next N lines will each contain M space-separated integers, guaranteed to be either 0 or 1. The input will end with a line with two 0s.
Output
For each test case, print a single integer, indicating the width (and height) of the largest square of all 1s, or 0 if there are no 1s. Print no extra spaces, and do not print any blank lines between answers.
Sample Input
Sample Output
Time Limit:4500MS Memory Limit:0KB 64bit IO Format:%lld & %llu
Submit Status Practice UVALive 4867
Description
Given an NxM matrix of all 1s and 0s, find the largest submatrix which is a square containing all 1s.
Input
There will be several test cases in the input. Each test case will begin with two integers, N and M(1
N, M
1, 000) indicating the number of rows and columns of the matrix. The next N lines will each contain M space-separated integers, guaranteed to be either 0 or 1. The input will end with a line with two 0s.
Output
For each test case, print a single integer, indicating the width (and height) of the largest square of all 1s, or 0 if there are no 1s. Print no extra spaces, and do not print any blank lines between answers.
Sample Input
4 5 0 1 0 1 1 1 1 1 1 1 0 1 1 1 0 1 1 1 1 1 3 4 1 1 1 1 1 1 1 1 1 1 1 1 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Sample Output
3 3 0
#include <cstdio> #include <cmath> #include <cstring> #include <ctime> #include <iostream> #include <algorithm> #include <set> #include <vector> #include <sstream> #include <queue> #include <typeinfo> #include <fstream> typedef long long ll; using namespace std; //freopen("D.in","r",stdin); //freopen("D.out","w",stdout); #define sspeed ios_base::sync_with_stdio(0);cin.tie(0) #define maxn 1010 const int inf=0x7fffffff; //无限大 int g[maxn][maxn]; int main() { int m,n; while(cin>>n>>m) { if(m==0&&n==0) break; memset(g,0,sizeof(g)); for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { cin>>g[i][j]; } } int ans=0; for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { if(i==0||j==0) { ans=max(g[i][j],ans); continue; } if(g[i][j]==0) continue; g[i][j]=min(g[i-1][j],min(g[i][j-1],g[i-1][j-1]))+1; ans=max(g[i][j],ans); } } cout<<ans<<endl; } return 0; }
相关文章推荐
- UVALive 7483 贪心策略
- Cross the Wall UVALive - 5097 (贪心+斜率dp)
- UVALive - 4621 Cav 贪心 + 分析
- UVALive 6604 Airport Sort(逆序对+贪心)
- UVALIVE 5000 Underwater Snipers(二分+贪心)
- UVaLive 3971 Assemble (水题二分+贪心)
- uvalive 4850(贪心)
- UVALive 4863 Balloons 贪心/费用流
- UVALive 3507:Keep the Customer Satisfied(贪心 Grade C)
- UVALive 4225 Prime Bases 贪心
- UVALive 2963-Hypertransmission-贪心
- UVALive-7146 Defeat the Enemy (map+贪心)
- uvalive5986(贪心)
- 初入算法篇(贪心)区间选点+uvalive2519
- UVALive 3177 长城守卫(贪心+二分)
- 例题1.8 彩色立方体 Colored Cubes UVALive - 3401 暴力打表+暴力搜索+贪心
- Bin Packing - UVALive 3503 贪心
- UVALive 6424 Russian Dolls 贪心
- UVALive 7416 贪心 multiset
- uvalive 2949(二分+贪心)