Malevich Strikes Back!
来源:互联网 发布:php中is numeric 编辑:程序博客网 时间:2024/05/14 14:31
1221. Malevich Strikes Back!
Time limit: 1.0 second
Memory limit: 64 MB
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
61 1 0 1 1 01 0 0 0 1 10 0 0 0 0 01 0 0 0 1 11 1 0 1 1 1 0 1 1 1 1 141 0 0 10 0 0 00 0 0 01 0 0 10
5No solution
/* 直接枚举图形的边长和中心,判断图形是否满足要求*/#include<iostream>#include<cstring>#include<cstdio>#include<cstdlib>#define MAXN 110using namespace std;int map[MAXN][MAXN];int n;int abs(int x,int y){ if(x<y) return y-x; else return x-y;}int check(int x,int y,int w){ if(y-w<1||y+w>n||x-w<1||x+w>n) return 0; for(int i=y-w; i<=y+w; i++) { for(int j=x-w; j<x-w+abs(i-y); j++) if(map[j][i]==0) return 0; for(int j=x-w+abs(i-y); j<=x+w-abs(i-y); j++) if(map[j][i]==1) return 0; for(int j=x+w; j>x+w-abs(i-y); j--) if(map[j][i]==0) return 0; } return 1;}int main(){ while(scanf("%d",&n)!=EOF&&n) { for(int i=1; i<=n; i++) { for(int j=1; j<=n; j++) scanf("%d",&map[i][j]); } int flag=0; for(int k=(n%2==0?n-1:n); k>=3; k-=2)//边长 { for(int i=1; i<n; i++) { for(int j=1; j<n; j++) { if(map[i][j]==0&&check(i,j,k/2))//(i,j)为中心 { flag=1; cout<<k<<endl;//碰到的第一个满足条件的k一定是最大的,从大到小枚举 break; } if(flag) break; } if(flag) break; } if(flag) break; } if(!flag) cout<<"No solution\n"; } return 0;}
- Malevich Strikes Back!
- URAL 1221. Malevich Strikes Back! 枚举 暴力
- URAL 1221 Malevich Strikes Back! (暴力枚举)
- URAL 1221 Malevich Strikes Back! (DP动态规划 O(n^2) )
- The Aqualizer Strikes Back!
- XST Strikes Back
- Kalevich Strikes Back
- SGU 319: Kalevich Strikes Back
- URAL 1646 Godzilla Strikes Back!
- sgu-319-Kalevich Strikes Back-线段树
- Ural 1520 Empire Strikes Back(模拟退火)
- CF 300E Empire Strikes Back
- sgu-234 Black-White King Strikes Back
- CodeForces 300E Empire Strikes Back
- SGU 319 Kalevich Strikes Back(线段树+扫描线)
- SGU 319 Kalevich Strikes Back(线段树扫描线)
- Kalevich Strikes Back(扫描线求分块的面积)
- sgu234:Black-White King Strikes Back(二分图匹配)
- java ==和equals的区别
- JAVA获取未来6天的天气预报
- 经典的量水问题
- hdu4619 Warm up 2(dfs)
- OpenCV 2 学习笔记(12): 算法的基本设计模式<3>:单例模式(Singleton pattern)
- Malevich Strikes Back!
- GraphLab集群搭建和测试
- ASIHTTPRequest类库简介和使用说明
- JAVA实现截取网页图片
- 1042. Shuffling Machine (20)-PAT
- 编程需要注意的事项
- 如果Jquery不存在 引用Jquery
- nginx内存池管理
- PYTHON 双引号 单引号 多引号区别