1221. Malevich Strikes Back!

Time limit: 1.0 second
Memory limit: 64 MB

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 ;
}

ural 1221. Malevich Strikes Back!的更多相关文章

  1. ural1221. Malevich Strikes Back!

    http://acm.timus.ru/problem.aspx?space=1&num=1221 算是枚举的 题目意思是必须划出这样的 11011 10001 00000 10001 110 ...

  2. ural 1221

    本来就是个很水的题  就是枚举起点长度然后直接判断就行了   但是比赛的时候写了个大bug 还找不出来     自己太水了 #include <cstdio> #include <c ...

  3. BZOJ 1221: [HNOI2001] 软件开发

    1221: [HNOI2001] 软件开发 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1428  Solved: 791[Submit][Stat ...

  4. 后缀数组 POJ 3974 Palindrome && URAL 1297 Palindrome

    题目链接 题意:求给定的字符串的最长回文子串 分析:做法是构造一个新的字符串是原字符串+反转后的原字符串(这样方便求两边回文的后缀的最长前缀),即newS = S + '$' + revS,枚举回文串 ...

  5. ural 2071. Juice Cocktails

    2071. Juice Cocktails Time limit: 1.0 secondMemory limit: 64 MB Once n Denchiks come to the bar and ...

  6. ural 2073. Log Files

    2073. Log Files Time limit: 1.0 secondMemory limit: 64 MB Nikolay has decided to become the best pro ...

  7. ural 2070. Interesting Numbers

    2070. Interesting Numbers Time limit: 2.0 secondMemory limit: 64 MB Nikolay and Asya investigate int ...

  8. ural 2069. Hard Rock

    2069. Hard Rock Time limit: 1.0 secondMemory limit: 64 MB Ilya is a frontman of the most famous rock ...

  9. ural 2068. Game of Nuts

    2068. Game of Nuts Time limit: 1.0 secondMemory limit: 64 MB The war for Westeros is still in proces ...

随机推荐

  1. 在mac上安装nodejs

    文章转载自我的个人博客  www.iwangzheng.com node.js最初是2009年发布的,目标是为聊实现事件驱动和非阻塞I/O的web服务器,应用的场景非常的广泛,有web服务器.实时应用 ...

  2. [HDU5015]233 Matrix

    [HDU5015]233 Matrix 试题描述 In our daily life we often use 233 to express our feelings. Actually, we ma ...

  3. 百度图片爬虫-python版

               self.browser=imitate_browser.BrowserBase()            self.chance=0            self.chanc ...

  4. ZeroMQ(java)之I/O线程的实现与组件间的通信

    算是开始读ZeroMQ(java)的代码实现了吧,现在有了一个大体的了解,看起来实现是比较的干净的,抽象什么的不算复杂... 这里先来看看它的I/O线程的实现吧,顺带看看是如何实现组件的通信的.... ...

  5. winform 添加“设置文件”

    添加配置文件 ·右击服务项目---添加新项---设置文件:----确定 ·把Settings1.settings,拖到properties里,双击Settings1.settings: 名称:是自己定 ...

  6. 把sql server 2000的用户表的所有者改成dbo

    怎么样把sql server 2000的用户表的所有者,改成dbo,而不是用户名. 推荐使用下面介绍的第二种方法,执行以下查询便可以了.sp_configure 'allow updates','1' ...

  7. Selenium webdriver 学习总结-元素定位

    Selenium webdriver 学习总结-元素定位 webdriver提供了丰富的API,有多种定位策略:id,name,css选择器,xpath等,其中css选择器定位元素效率相比xpath要 ...

  8. Emacs 24.3 配置JDEE(http://blog.csdn.net/csfreebird/article/details/19033939)

    最近要重回Java编程,所以打算在最新版本的Emacs 24.3上配置JDEE,听说会有些问题,特此记录安装过程. Emacs 24.3内置了CEDET, 版本是2.0, 这是一个让人困惑的事情,因为 ...

  9. PHP---TP框架---添加数据-----有三种方式

    添加数据 添加数据有三种方式: 第一种: <?php namespace Home\Controller;//这个文件的命名空间 use Think\Controller;//use使用哪一个而 ...

  10. emmet中文文档 (转载)

    Emmet的前身是大名鼎鼎的Zen coding,如果你从事Web前端开发的话,对该插件一定不会陌生.它使用仿CSS选择器的语法来生成代码,大大提高了HTML/CSS代码编写的速度,比如下面的演示: ...