USACO/range 3.3.4
2013-05-23 16:13
246 查看
这个题不是很难的,比上个要简单很多,其实上一个我还没有写出来 的。。。
/*如果以(i,j)为顶点边长为k的正方形那么判断其是否
存在k+1的边,只要判断第(i+k)行和(j+k)列就好
*/
#include <stdio.h>
#include <stdlib.h>
int ans[260]={0};
int row[260][260]={0}; //row[i][j]表示第i行前j个的和
int column[260][260]={0}; //column[i][j]表示处j列前i行的和
void creat(int p,int q,int n,int ars[][260])
{
int f,t;
for(f=1;f<=n;f++)
{
if(row[p+f][q+f]-row[p+f][q-1]==(f+1)&&
column[q+f][p+f]-column[q+f][p-1]==(f+1)) //检查第p+f行和q+f列是否全为1
{
ans[f+1]++; //表示以(p,q)为左上角边长为f的正方形存在
}
else
{
return;
}
}
}
void deal(int ars[][260],int n)
{
int i,j;
for(i=0;i<n-1;i++)
{
for(j=0;j<n-1;j++)
{
if(ars[i][j]) //是1才有可能是构成正方形
creat(i,j,n,ars);
}
}
}
int main()
{
FILE *fin=fopen("range.in","r");
FILE *fout=fopen("range.out","w");
int n;
int square[260][260]={0};
char s[260][260]={0};
int i ,j;
fscanf(fin,"%d",&n);
for(i=0;i<n;i++)
{
fscanf(fin,"%s",s[i]);
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
square[i][j]=s[i][j]-'0';
}
}
for(i=0;i<n;i++) //预处理
{
row[i][0]=square[i][0];
column[i][0]=square[0][i];
for(j=1;j<n;j++)
{
row[i][j]=row[i][j-1]+square[i][j];
column[i][j]=column[i][j-1]+square[j][i];
}
}
deal(square,n);
for(j=2;j<=n;j++)
{
if(ans[j])
{
fprintf(fout,"%d %d\n",j,ans[j]);
}
}
return 0;
}
/*如果以(i,j)为顶点边长为k的正方形那么判断其是否
存在k+1的边,只要判断第(i+k)行和(j+k)列就好
*/
#include <stdio.h>
#include <stdlib.h>
int ans[260]={0};
int row[260][260]={0}; //row[i][j]表示第i行前j个的和
int column[260][260]={0}; //column[i][j]表示处j列前i行的和
void creat(int p,int q,int n,int ars[][260])
{
int f,t;
for(f=1;f<=n;f++)
{
if(row[p+f][q+f]-row[p+f][q-1]==(f+1)&&
column[q+f][p+f]-column[q+f][p-1]==(f+1)) //检查第p+f行和q+f列是否全为1
{
ans[f+1]++; //表示以(p,q)为左上角边长为f的正方形存在
}
else
{
return;
}
}
}
void deal(int ars[][260],int n)
{
int i,j;
for(i=0;i<n-1;i++)
{
for(j=0;j<n-1;j++)
{
if(ars[i][j]) //是1才有可能是构成正方形
creat(i,j,n,ars);
}
}
}
int main()
{
FILE *fin=fopen("range.in","r");
FILE *fout=fopen("range.out","w");
int n;
int square[260][260]={0};
char s[260][260]={0};
int i ,j;
fscanf(fin,"%d",&n);
for(i=0;i<n;i++)
{
fscanf(fin,"%s",s[i]);
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
square[i][j]=s[i][j]-'0';
}
}
for(i=0;i<n;i++) //预处理
{
row[i][0]=square[i][0];
column[i][0]=square[0][i];
for(j=1;j<n;j++)
{
row[i][j]=row[i][j-1]+square[i][j];
column[i][j]=column[i][j-1]+square[j][i];
}
}
deal(square,n);
for(j=2;j<=n;j++)
{
if(ans[j])
{
fprintf(fout,"%d %d\n",j,ans[j]);
}
}
return 0;
}
相关文章推荐
- USACO3.3.4 Home on the Range (range)
- [USACO3.3.4]Home on the Range
- USACO3.3.4--Home on the Range
- USACO3.3.4 Home on the Range (range)
- USACO 3.3 Home on the Range (range)
- USACO Home on the Range
- USACO / Home on the Range (DP统计正方形个数)
- USACO-Section 3.3- PROB Home on the Range
- usaco Home on the Range
- usaco3.3.4亚瑟王的宫殿
- [USACO3.3]家的范围 Home on the Range
- usaco--range
- USACO--3.3Home on the Range+DP
- [USACO]Home on the Range
- USACO 3.3.4
- usaco 3.3 Home on the Range
- USACO home on the range C 语言实现
- USACO Section 3.3 Home on the Range
- usaco 3.3 range 2008.11.7
- USACO-Section 3.3 Home on the Range (树状数组||DP)