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
  1. 6
  2. 1 1 0 1 1 0
  3. 1 0 0 0 1 1
  4. 0 0 0 0 0 0
  5. 1 0 0 0 1 1
  6. 1 1 0 1 1 1
  7. 0 1 1 1 1 1
  8. 4
  9. 1 0 0 1
  10. 0 0 0 0
  11. 0 0 0 0
  12. 1 0 0 1
  13. 0
  1. 5
  2. No solution
Problem Author: Nikita Shamgunov
Problem Source: The Seventh Ural State University collegiate programming contest
Difficulty: 432
 
题意:给出一个n*n的黑白染色的矩阵,如果有一个白色的斜着的(逆时针转45°)正方形,把这个正方形不成一个大的正方形,补上去的那部分都是黑色的话,就是合法的。
问最大的合法的白色正方形的斜边是多少?具体看样例。
分析:暴力枚举那个斜边,然后暴力判断。只有一个点不算正方形
 
  1. #include <cstdio>
  2. #include <cstring>
  3. #include <cstdlib>
  4. #include <cmath>
  5. #include <deque>
  6. #include <vector>
  7. #include <queue>
  8. #include <iostream>
  9. #include <algorithm>
  10. #include <map>
  11. #include <set>
  12. #include <ctime>
  13. using namespace std;
  14. typedef long long LL;
  15. typedef double DB;
  16. #define For(i, s, t) for(int i = (s); i <= (t); i++)
  17. #define Ford(i, s, t) for(int i = (s); i >= (t); i--)
  18. #define Rep(i, t) for(int i = (0); i < (t); i++)
  19. #define Repn(i, t) for(int i = ((t)-1); i >= (0); i--)
  20. #define rep(i, x, t) for(int i = (x); i < (t); i++)
  21. #define MIT (2147483647)
  22. #define INF (1000000001)
  23. #define MLL (1000000000000000001LL)
  24. #define sz(x) ((int) (x).size())
  25. #define clr(x, y) memset(x, y, sizeof(x))
  26. #define puf push_front
  27. #define pub push_back
  28. #define pof pop_front
  29. #define pob pop_back
  30. #define ft first
  31. #define sd second
  32. #define mk make_pair
  33. inline void SetIO(string Name) {
  34. string Input = Name+".in",
  35. Output = Name+".out";
  36. freopen(Input.c_str(), "r", stdin),
  37. freopen(Output.c_str(), "w", stdout);
  38. }
  39.  
  40. inline int Getint() {
  41. int Ret = ;
  42. char Ch = ' ';
  43. while(!(Ch >= '' && Ch <= '')) Ch = getchar();
  44. while(Ch >= '' && Ch <= '') {
  45. Ret = Ret*+Ch-'';
  46. Ch = getchar();
  47. }
  48. return Ret;
  49. }
  50.  
  51. const int N = ;
  52. int n, Map[N][N];
  53.  
  54. inline void Solve();
  55.  
  56. inline void Input() {
  57. while(~scanf("%d", &n) && n) {
  58. For(i, , n)
  59. For(j, , n) scanf("%d", &Map[i][j]);
  60. Solve();
  61. }
  62. }
  63.  
  64. inline bool Check(int x, int y, int r) {
  65. r /= ;
  66. if(x-r < || x +r > n || y-r < || y+r > n) return ;
  67. For(j, y-r, y+r) {
  68. For(i, x-r, x-r+abs(j-y)-)
  69. if(!Map[i][j]) return ;
  70. For(i, x+r-abs(j-y)+, x+r)
  71. if(!Map[i][j]) return ;
  72.  
  73. For(i, x-r+abs(j-y), x+r-abs(j-y))
  74. if(Map[i][j]) return ;
  75. }
  76. return ;
  77. }
  78.  
  79. inline void Solve() {
  80. int m = n;
  81. bool Flag = ;
  82. if(!(m&)) m--;
  83. while(m >= ) {
  84. For(i, , n) {
  85. For(j, , n)
  86. if(!Map[i][j] && Check(i, j, m)) {
  87. Flag = ;
  88. break;
  89. }
  90. if(Flag) break;
  91. }
  92. if(Flag) break;
  93. m -= ;
  94. }
  95.  
  96. if(Flag) printf("%d\n", m);
  97. else puts("No solution");
  98. }
  99.  
  100. int main() {
  101. #ifndef ONLINE_JUDGE
  102. SetIO("E");
  103. #endif
  104. Input();
  105. //Solve();
  106. return ;
  107. }

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. 淘宝(阿里百川)手机客户端开发日记第八篇 Handler的使用方法

    首先,我们先看下API文档的说明: A Handler allows you to send and process Message and Runnable objects associated w ...

  2. Linux下网络故障诊断

    导读 由于实现网络服务器的层次结构比较多,因此当网络出现故障时,解决起来比较复杂.下面由我来为大家详细介绍Linux系统中可能出现的一些网络问题,如网卡硬件问题.网络配置问题.驱动程序问题,以及网络层 ...

  3. bmob

    移动后台: bmob http://baike.baidu.com/link?url=GHdwJY3cGygcfQDdzosckQnhVy1pvIGZA2Ws0K26lSSFGu7QRX4R1wlo6 ...

  4. FZU 1649 Prime number or not米勒拉宾大素数判定方法。

    C - Prime number or not Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%I64d & % ...

  5. linux /etc/rc.d/目录的详解

    rc.d的内容如下: init.d/ :各种服务器和程序的二进制文件存放目录. rcx.d/: 各个启动级别的执行程序连接目录.里头的东西都是指向init.d/的一些软连接.具体的后边叙述. 还有三个 ...

  6. Jquery获取数据并生成下拉菜单

    <script type="text/javascript"> $(document).ready(function() { GetByJquery(); $(&quo ...

  7. MVC NonAction属性

    3.1. NonAction属性 若将NonAction属性应用在Controller中的Action方法上,即使该Action方法是公共方法,也会告知ActionInvoker不要选取这个Actio ...

  8. 58. 分析、测试与总结:罗马数字和阿拉伯数字的转换[roman to integer and integer to roman in c++]

    [本文链接] http://www.cnblogs.com/hellogiser/p/roman-to-integer-and-integer-to-roman.html [题目] 给出一个罗马数字, ...

  9. Java for LeetCode 072 Edit Distance【HARD】

    Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2 ...

  10. QQ图片名字

    ﻩ并亲了你一下ﻩ大兔子҉҉大兔子҉҉҉҉҉҉҉҉