250 - Pattern Matching Prelims
Posted: Fri Jan 09, 2004 8:45 pm
Can anyone think of any weird input/output for this problem? As far as I can tell, it's a pretty straight forward counting problem, but I keep getting WA...
I think the gravity column can be any of the valid columns.zizi wrote:What's the correct data set for this problem . ??
I have another question ,can the i comlumn of the gravity be m and or j column be n?
Code: Select all
5 5
0.1 0.2 0.1 0.2 0.1
0.1 0.2 0.3 0.1 0.1
0.2 0.3 0.1 0.1 0.3
0.4 0.1 0.1 0.1 0.2
0.2 0.2 0.3 0.3 0.1
5 10
0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1
0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2 0.2
0.3 0.3 0.3 0.3 0.3 0.3 0.3 0.3 0.3 0.3
0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4 0.4
0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.6
3 3
0.0 0.0 0.0
0.0 0.0 0.0
0.0 0.0 0.0
1 1
0.5
5 5
0.1 0.1 0.1 0.1 0.9
0.2 0.2 0.2 0.2 0.9
0.3 0.7 0.3 0.9 0.9
0.4 0.4 0.4 0.9 0.9
0.5 0.5 0.5 0.5 0.9
5 5
0.1 0.1 0.1 0.1 0.9
0.2 0.2 0.2 0.2 0.9
0.3 0.11 0.3 0.9 0.9
0.4 0.44 0.4 0.9 0.9
0.5 0.15 0.25 0.5 0.9
5 5
0.1 0.1 0.1 0.1 0.3
0.2 0.2 0.0002 0.2 0.2
0.3 0.12 0.3 0.9 0.1
0.4 0.4 0.4 0.9 0.9
0.5 0.5 0.5 0.5 0.9
5 5
0.1 0.1 0.1 0.1 0.6
0.2 0.2 0.2 0.2 0.004
0.3 0.7 0.3 0.2 0.1
0.4 0.4 0.4 0.9 0.1
0.5 0.5 0.5 0.5 0.1
5 5
0.1 0.1 0.1 0.1 0.9
0.2 0.2 0.2 0.3 0.9
0.3 0.17 0.3 0.4 0.9
0.4 0.14 0.4 0.1 0.9
0.5 0.5 0.15 0.5 0.99
10 10
0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1
0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1
0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1
0.1 0.1 0.1 0.2 0.1 0.1 0.1 0.1 0.1 0.1
0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1
0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1
0.77 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.99 0.1
0.1 0.88 0.1 0.1 0.77 0.1 0.1 0.1 0.1 0.1
0.1 0.1 0.66 0.1 0.17 0.1 0.1 0.9 0.1 0.00001
0.1 0.1 0.1 0.90 0.880 0.1 0.1 0.99 0.00001 0.222
0 0
Code: Select all
Case 1: center at (3, 3)
Case 2: center at (4, 6)
Case 3: center at (3, 3)
Case 4: center at (1, 1)
Case 5: center at (3, 4)
Case 6: center at (3, 4)
Case 7: center at (4, 4)
Case 8: center at (4, 3)
Case 9: center at (3, 4)
Case 10: center at (7, 5)
Code: Select all
#include<stdlib.h>
#include<stdio.h>
#define MAX 26
#define INF 1000000000000
long double arr[MAX][MAX];
int Row,Col;
int ansR,ansC;
long double smallRow,smallCol;
void compute(int r,int c){
long double tempA,tempB,res,res2;
int i,j;
tempA=tempB=0;
for(i=r-1;i>=0;i--)
for(j=0;j<Col;j++) tempA+=arr[i][j];
for(i=r+1;i<Row;i++)
for(j=0;j<Col;j++) tempB+=arr[i][j];
if(tempA>tempB) res=tempA-tempB;
else res=tempB-tempA;
tempA=tempB=0;
for(i=0;i<Row;i++)
for(j=c-1;j>=0;j--) tempA+=arr[i][j];
for(i=0;i<Row;i++)
for(j=c+1;j<Col;j++) tempB+=arr[i][j];
if(tempA>tempB) res2=tempA-tempB;
else res2=tempB-tempA;
if(res2<=smallCol&&res<=smallRow) {smallRow=res;smallCol=res2;ansR=r;ansC=c;}
}
void main(){
int r,c;
int i,j,no=0;
long double temp;
while(scanf("%d %d",&Row,&Col)==2)
{
if(!Row&&!Col) break;
++no;
smallRow=smallCol=INF;
for(i=0;i<Row;i++)
for(j=0;j<Col;j++)
{
scanf("%Lf",&temp);
arr[i][j]=temp;
}
for(i=0;i<Row;i++)
for(j=0;j<Col;j++)
compute(i,j);
printf("Case %d: center at (%d, %d)\n",no,ansR+1,ansC+1);
}
}
Hmm.. I'm not sure if your WAs are caused by precision error..algoJo wrote:Hi, I think this problem is straightforward, but it gives me multiple WA..., can anyone give me some hints? I'm very very curious bout this problem...
Thanks![]()
Code: Select all
... if(res2<=smallCol&&res<=smallRow) {smallRow=res;smallCol=res2;ansR=r;ansC=c;} ...
Code: Select all
if(res2+1e-6<=smallCol+1e-6&&res+1e-6<=smallRow+1e-6) {smallRow=res;smallCol=res2;ansR=r;ansC=c;}