ural 1221. Malevich Strikes Back!

时间:2021-07-12 05:06:34

1221. Malevich Strikes Back!

Time limit: 1.0 second
Memory limit: 64 MB
ural 1221. Malevich Strikes Back!
After the greatest success of Malevich's "Black Square" the famous artist decided to create a new masterpiece. He took a large sheet of checked paper and filled some cells with black. After that he realized the picture to be too complicated. He was afraid, that people would not understand the sense of the painting. Thus, Malevich decided to cut out a smaller picture of the special form. It should be a black square with its sides parallel to the sides of the list. A white square rotated by 45 degrees should be placed inside the black square. The corners of the white square should lay on the sides of the black square. You can see an example of such picture on the figure.
The original paper size is N × N, 0 < N ≤ 100. Your program should help Malevich to find the largest figure corresponding to the pattern described above.

Input

The input contains several test cases. Each test case starts with the size of paper N. The followingN lines of the test case describe the original painting: "1" denotes a black and "0" denotes a white cell. End of the input is marked by a zero value for N.

Output

Your program should output the size (i.e. the maximum width or height) of the largest figure, which Malevich would like to cut out. If no such figure exists, output "No solution".

Sample

input output
6
1 1 0 1 1 0
1 0 0 0 1 1
0 0 0 0 0 0
1 0 0 0 1 1
1 1 0 1 1 1
0 1 1 1 1 1
4
1 0 0 1
0 0 0 0
0 0 0 0
1 0 0 1
0
5
No solution
Problem Author: Nikita Shamgunov
Problem Source: The Seventh Ural State University collegiate programming contest
Difficulty: 432
 
题意:给出一个n*n的黑白染色的矩阵,如果有一个白色的斜着的(逆时针转45°)正方形,把这个正方形不成一个大的正方形,补上去的那部分都是黑色的话,就是合法的。
问最大的合法的白色正方形的斜边是多少?具体看样例。
分析:暴力枚举那个斜边,然后暴力判断。只有一个点不算正方形
 
 #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <ctime>
using namespace std;
typedef long long LL;
typedef double DB;
#define For(i, s, t) for(int i = (s); i <= (t); i++)
#define Ford(i, s, t) for(int i = (s); i >= (t); i--)
#define Rep(i, t) for(int i = (0); i < (t); i++)
#define Repn(i, t) for(int i = ((t)-1); i >= (0); i--)
#define rep(i, x, t) for(int i = (x); i < (t); i++)
#define MIT (2147483647)
#define INF (1000000001)
#define MLL (1000000000000000001LL)
#define sz(x) ((int) (x).size())
#define clr(x, y) memset(x, y, sizeof(x))
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
#define ft first
#define sd second
#define mk make_pair
inline void SetIO(string Name) {
string Input = Name+".in",
Output = Name+".out";
freopen(Input.c_str(), "r", stdin),
freopen(Output.c_str(), "w", stdout);
} inline int Getint() {
int Ret = ;
char Ch = ' ';
while(!(Ch >= '' && Ch <= '')) Ch = getchar();
while(Ch >= '' && Ch <= '') {
Ret = Ret*+Ch-'';
Ch = getchar();
}
return Ret;
} const int N = ;
int n, Map[N][N]; inline void Solve(); inline void Input() {
while(~scanf("%d", &n) && n) {
For(i, , n)
For(j, , n) scanf("%d", &Map[i][j]);
Solve();
}
} inline bool Check(int x, int y, int r) {
r /= ;
if(x-r < || x +r > n || y-r < || y+r > n) return ;
For(j, y-r, y+r) {
For(i, x-r, x-r+abs(j-y)-)
if(!Map[i][j]) return ;
For(i, x+r-abs(j-y)+, x+r)
if(!Map[i][j]) return ; For(i, x-r+abs(j-y), x+r-abs(j-y))
if(Map[i][j]) return ;
}
return ;
} inline void Solve() {
int m = n;
bool Flag = ;
if(!(m&)) m--;
while(m >= ) {
For(i, , n) {
For(j, , n)
if(!Map[i][j] && Check(i, j, m)) {
Flag = ;
break;
}
if(Flag) break;
}
if(Flag) break;
m -= ;
} if(Flag) printf("%d\n", m);
else puts("No solution");
} int main() {
#ifndef ONLINE_JUDGE
SetIO("E");
#endif
Input();
//Solve();
return ;
}