hdu4331 Image Recognition
来源:互联网 发布:网络验证哪款好 编辑:程序博客网 时间:2024/04/29 10:40
Image Recognition
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 964 Accepted Submission(s): 371
Problem Description
Now there is an image recognition problem for you. Now you are given an image which is a N * N matrix and there are only 0s and 1s in the matrix. And we are interested in the squares in whose four edges there is no 0s. So it’s your task to find how many such squares in the image.
Input
The first line of the input contains an integer T (1<=T<=10) which means the number of test cases.
For each test cases, the first line is one integer N (1<=N<=1000) which is the size of the image. Then there are N lines and each line has N integers each of which is either 0 or 1.
For each test cases, the first line is one integer N (1<=N<=1000) which is the size of the image. Then there are N lines and each line has N integers each of which is either 0 or 1.
Output
For each test case, please output a line which is "Case X: Y", X means the number of the test case and Y means the number of the squares we are interested in in the image.
Sample Input
131 1 01 1 00 0 0
Sample Output
Case 1: 5
Source
2012 Multi-University Training Contest 4
Recommend
zhoujiaqi2010
正归的做法应该是线段树,没想到用暴力过了,呵呵
#include <iostream>#include <stdio.h>#include <string.h>using namespace std;#define MAXN 1005int up[MAXN][MAXN];int lleft[MAXN][MAXN];int map[MAXN][MAXN];int fmin(int a,int b){ if(a<b) return a; return b;}int main(){ int n,tcase,i,j,t=1; int ans; scanf("%d",&tcase); while(tcase--) { scanf("%d",&n); ans=0; memset(lleft,0,sizeof(lleft)); memset(up,0,sizeof(up)); for(i=1;i<=n;i++) for(j=1;j<=n;j++) { scanf("%d",&map[i][j]); if(map[i][j]) { ans++; lleft[i][j]=lleft[i][j-1]+1; up[i][j]=up[i-1][j]+1; } else { lleft[i][j]=0; up[i][j]=0; } } for(i=1;i<=n;i++) { for(j=1;j<=n;j++) { int k=fmin(up[i][j],lleft[i][j]); if(k<=1) continue; int temp; for(temp=2;temp<=k;temp++) { if(up[i][j-temp+1]>=temp&&lleft[i-temp+1][j]>=temp) { ans++; } } } } printf("Case %d: %d\n",t++,ans); } return 0;}
- hdu4331 Image Recognition
- HDU4331 Image Recognition
- hdu4331-Image Recognition-多校4-题解
- HDU4331 Image Recognition 树状数组+扫描线
- hdu4331 Image Recognition 就暴力啊。。啊。。
- 2012 Multi-University Training Contest 4-1001 hdu4331 Image Recognition
- Image Recognition
- Image Recognition
- Image Recognition
- HDU 4331 - Image Recognition
- HDU Image Recognition
- hdu 4331 Image Recognition
- hdu 4331 Image Recognition
- hdu 4331 Image Recognition
- 4331-Image Recognition
- Image Recognition(暴力+优化)
- Image Recognition and Face Detection
- HDU 4331 Image Recognition 题解
- Android 按键消息处理
- Android Storage Manager 处理
- 公司新人培训心得
- dsPIC33F的IGBT控制PWM
- VirtualBox下的ubuntu虚拟机之间通讯的网络配置
- hdu4331 Image Recognition
- 3.2.2 单链表类节点的释放
- ADT版本号超过17后,所遇到的问题,如导入项目没有Android Dependencies目录、jars包导入的解决办法
- 命令行运行hadoop的HelloWorld,word count - 总结
- tomcat 6/7 maven 自动发布+热部署方法
- HDU 1106 排序
- CSS的一些常识
- 杭电1163--Eddy's digital Roots (九余数定理)
- Call JavaScript from server side