|
|
back to boardIs this algorythm right? Posted by pes 25 Sep 2002 19:45 Hello everybody! I have used an algorythm that i'm not sure there is or isn't some subtle stupidity. It is very simple: You present the grid by the crossroads and for each crossroad you find the max number of diagonals(MD) that you can go through from the start point( crossroad 0,0 ) to the concerned crossroad (of course this will be the shortest way to it). Then you can assume that the paths to all the crossroads which are on north , east or north-east from this crossroad pass through this point is shorter by MD*( 200-100*sqrt(2) ) from the standart(with no diagonals). I stop explaining here, `cause my english is awlful, and i may confuse you. The code is short so i hope you understand it easily. So if you can prove that it is wrong or can give me some test with wa, I`ll be very grateful... #include <iostream.h> #include <math.h> void printks(); class point{ //the crossroads public: int x, y; //the coords int dgs; // the number of diagonals that lead to that crossroad, //if you take the shortest path point(){ dgs=0; } } ks[110]; int k, n, m, cinx, ciny, tmpdgs, ind=0, indbr; double long answer; int main(){ cin>>n>>m>>k;
for (int br=0; br<k; br++){ cin>>cinx>>ciny;
tmpdgs=0; for ( indbr=0; indbr<ind; indbr++ ) if ( (cinx-1)>=ks[indbr].x && (ciny-1)>=ks[indbr].y ) if ( ks[indbr].dgs>tmpdgs ) tmpdgs= ks [indbr].dgs;
ks[ind].x=cinx; ks[ind].y=ciny; ks[ind].dgs=tmpdgs+1; ind++; }
tmpdgs=0; for ( indbr=0; indbr<ind; indbr++ ) if ( n>=ks[indbr].x && m>=ks[indbr].y && ks [indbr].dgs>tmpdgs ) tmpdgs=ks[indbr].dgs; answer= (n+m-2*tmpdgs)*100+sqrt(2)*100*tmpdgs ;
if ( answer-floorl(answer)<=(long double)(0.49999999999) ) cout<<(long)(floorl(answer))<<endl; else cout<<(long)(ceill(answer))<<endl; return 0; } |
|
|