|
|
вернуться в форумWhere is my error ? I got WA . Can you help me ! Pls Here is my source : #include <stdio.h> #include <math.h> int m,n,k,primary=1,second=0; char x[1100][130]; double min[2][1100]; void read_data() { int i,mod,_div,a,b; FILE *f=stdin; fscanf(f,"%d%d%d",&n,&m,&k); n++;m++; for(i=0;i<k;i++) { fscanf(f,"%d%d",&a,&b); mod=a & 7; _div=a >> 3; x[b][_div]=x[b][_div] | (1 << mod); } } double minim(double a,double b) { return(a<=b?a:b); } void solve() { int i,j,mod,_div; min[second][1]=0; for(i=2;i<=n;i++)min[second][i]=(i-1)*100; for(i=2;i<=m;i++) { min[primary][1]=min[second][1]+100; for(j=2;j<=n;j++) { min[primary][j]=minim(min[primary][j-1]+100,min[second][j]+100); mod=(j-1) & 7;_div=(j-1) >> 3; if(x[i-1][_div] & (1 << mod)) min[primary][j]=minim(min[primary][j],min[second][j-1]+ (141.42135)); } second=!second;primary=!primary; } } void print() { printf("%ld",(long)ceil(min[second][n])); } void main() { read_data(); solve(); print(); } Mhm....(+) I started making corrections to your code, but after a while i saw that you haven't understand the idea of the problem (for n, for m, is absolutly wrong and unnecesary). Hint: You can do it in O(k^2)[i remind k is the number of diagonals]. Goos Luck! Re: Mhm....(+) > I started making corrections to your code, but after a while i saw > that you haven't understand the idea of the problem (for n, for m, is > absolutly wrong and unnecesary). Hint: You can do it in O(k^2)[i > remind k is the number of diagonals]. > Goos Luck! OK ! Thank you ! |
|
|