标签:des style blog http color io os java ar
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 841 Accepted Submission(s): 296
1 #include<cstdio> 2 #include<cstring> 3 #include<cstdlib> 4 using namespace std; 5 const int maxn=2005; 6 char map[maxn][maxn]; 7 int n,m; 8 bool match(int posx,int posy,int x,int y) 9 { 10 int i,j; 11 if(posx+x>n||posx<0||posy+y>m||posy<0) 12 return 0; 13 for( i=posx; i<posx+x ; i++ ){ 14 for( j=posy ; j<posy+y ; j++ ) { 15 if(map[i][j]!=‘*‘)return false; 16 } 17 } 18 return true; 19 } 20 21 int work(int x,int y) 22 { 23 int i,j,cnt=0; 24 for(i=0;i<n;i++){ 25 for(j=0;j<m;j++){ 26 if(match(i,j,x,y)) cnt++; 27 if(match(i,j,y,x)) cnt++; 28 } 29 } 30 return cnt; 31 } 32 int main() 33 { 34 int x,y,i; 35 while(scanf("%d%d",&n,&m)!=EOF,n+m!=0) 36 { 37 scanf("%d%d",&x,&y); 38 for(i=0;i<n;i++) 39 scanf("%s",map[i]); 40 printf("%d\n",work(x,y)); 41 } 42 return 0; 43 }
然后统计了一下,dp...简单的dp
代码: 不过依旧还是很挫,写到了680ms....
1 #include<cstdio> 2 #include<cstring> 3 #include<cstdlib> 4 using namespace std; 5 const int maxn=2005; 6 char map[maxn][maxn]; 7 int dp[maxn][maxn]; 8 int n,m; 9 void init() 10 { 11 int i,j,cnt=0; 12 memset(dp,0,sizeof(dp)); 13 for(i=1;i<=n;i++) { 14 for(j=1;j<=m;j++) { 15 if(map[i][j-1]==‘*‘)cnt++; 16 dp[i][j]=cnt+dp[i-1][j]; 17 } 18 cnt=0; 19 } 20 } 21 int work(int x,int y){ 22 int i,j,cnt=0; 23 for(i=1;i+x<=n;i++){ 24 for(j=1;j+y<=m;j++){ 25 int tem=dp[i+x][j+y]-dp[i-1][j+y]-dp[i+x][j-1]+dp[i-1][j-1]; 26 if(tem==((x+1)*(y+1)))cnt++; 27 } 28 } 29 return cnt; 30 } 31 int main() 32 { 33 int x,y,i; 34 while(scanf("%d%d",&n,&m),n+m!=0) 35 { 36 scanf("%d%d",&x,&y); 37 x--,y--; 38 for(i=1;i<=n;i++) 39 scanf("%s",map[i]); 40 init(); 41 if(x==y) printf("%d\n",work(x,y)); 42 else printf("%d\n",work(x,y)+work(y,x)); 43 44 } 45 return 0; 46 }
hdu ---(4517)小小明系列故事——游戏的烦恼(Dp)
标签:des style blog http color io os java ar
原文地址:http://www.cnblogs.com/gongxijun/p/3975619.html