| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
啊? 昨晚在自习室里想出来的点现在测又是对的了, 我把程序放在这里 dynamic帮忙看一下啊 我算法里的一个地方确实还没有证明In Reply To:hawk , 你再测测, 我的程序对这个点应该有问题, 把它加到测试数据里吧 Posted by:rruucc at 2003-11-04 07:37:16 #include<stdio.h>
#include<string.h>
#define MaxN 201
int m,n,r,c;
double mar[MaxN][MaxN];
double map[MaxN];
int x1,y1,x2,y2;
int xx1,yy1,xx2,yy2;
double tmp,max;
int init()
{ int i,j;
memset(mar,0,sizeof(mar));
scanf("%d",&m); if (m==0) return 0;
scanf("%d %d %d",&n,&r,&c);
for (i=1; i<=m; i++)
for (j=1; j<=n; j++)
{scanf("%lf",&mar[i][j]); mar[i][j]+=mar[i-1][j];}
return 1;
}
void save()
{max=tmp/(y2-y1+1);
xx1=x1; yy1=y1; xx2=x2; yy2=y2;
}
void check()
{if (tmp/(y2-y1+1)>max)
save();
else if (tmp/(y2-y1+1)==max)
{if (x1<xx1)
save();
else if (x1==xx1&&y1<yy1)
save();
else if (x1==xx1&&y1==yy1&&x2<xx2)
save();
else if (x1==xx1&&y1==yy1&&x2==xx2&&y2<yy2)
save();
}
}
void minmap()
{ int i;
for (map[0]=0,i=1; i<=n; i++) map[i]=map[i-1]+map[i];
tmp=map[c]; y1=1; y2=c; check();
for (i=c+1; i<=n; i++)
{if ((tmp+map[i]-map[i-1])/(y2-y1+1+1)>=(map[i]-map[i-c])/c)
{tmp=tmp+map[i]-map[i-1]; y2++;}
else
{tmp=(map[i]-map[i-c]); y2++; y1=y2-c+1;}
check();
}
}
void search()
{ int i;
max=-1; xx1=-1; yy1=-1; xx2=-1; yy2=-1;
for (x1=1; x1<=m; x1++)
for (x2=x1+r-1; x2<=m; x2++)
{for (i=1; i<=n; i++) map[i]=(mar[x2][i]-mar[x1-1][i])/(x2-x1+1);
minmap();
}
printf("%d %d %d %d\n",xx1,yy1,xx2,yy2);
}
int main()
{while (init())
search();
printf("*\n");
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator