218 - WA

All about problems in Volume II. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

218 - WA

Postby snar » Tue May 09, 2006 7:10 pm

Please, give me some test data for this problem.

Code: Select all
#include <stdio.h>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std ;
#define EPS 1e-7

struct P        { double x, y; P() {}; P( double q, double w ) : x( q ), y( w ) {}         };
P operator -    ( const P &p, const P &q ) { P u( p.x - q.x, p.y - q.y ); return u;  }
bool operator !=( const P &p, const P &q ) { return fabs(p.x - q.x)>EPS || fabs(p.y - q.y)>EPS;}

vector<P> JarvisMarch ( vector<P> Q )
{
   vector<P> S ;
   P p, q ;
   int i, n ;   
   n = Q.size( ) ;
       p = Q[0] ;
   for ( i=1; i<n; i++ )
      if ( Q[i].y < p.y-EPS )
         p = Q[i] ;
      else
         if ( fabs( Q[i].y - p.y ) < EPS )
            if ( Q[i].x < p.x-EPS )   
               p = Q[i] ;         
   do
   {
     S.push_back ( p ) ;
     p = Q[0] ;
     q = S.back( ) ;
     for ( i=1; i<n; i++ )
         p = ( Q[i] - q ).x * ( p - q ).y - ( Q[i] - q ).y * ( p - q ).x > EPS ||
        ( fabs(( Q[i] - q ).x * ( p - q ).y - ( Q[i] - q ).y * ( p - q ).x) < EPS && ( Q[i] - q ).x * ( Q[i] - q ).x + ( Q[i] - q ).y * ( Q[i] - q ).y >
        ( p - q ).x * ( p - q ).x + ( p - q ).y * ( p - q ).y+EPS ) ? Q[i] : p ;        
   }
   while ( p != S[0] ) ;
   return S ;
}

vector<P> Q ;

void main() {
   P p ;
   int n,it,i,j;
   double perimeter ;
   it=1;
   while  ( scanf ( "%d", &n ),n ) {
      Q.clear ( ) ;
      for(i=0; i<n; i++) {
         scanf("%lf%lf",&p.x,&p.y) ;
         Q.push_back ( p ) ;
      }
       
      Q = JarvisMarch ( Q ) ;      
      
      n = Q.size ( ) ;

      perimeter = 0.0 ;      
        for    ( i=n-1,j=0; j<n; i=j++ )
         perimeter += sqrt ( (Q[i].x-Q[j].x)*(Q[i].x-Q[j].x) + (Q[i].y-Q[j].y)*(Q[i].y-Q[j].y) ) ;
      
      printf ( "Region #%d:\n(%.1lf,%.1lf)", it++,Q[0].x+EPS,Q[0].y+EPS ) ;
      for    ( i=n-1; i>=0; i-- ) printf ( "-(%.1lf,%.1lf)", Q[i].x+EPS, Q[i].y+EPS ) ;
      putchar( '\n' ) ;
        printf ( "Perimeter length = %.2lf\n\n", perimeter+EPS ) ;      
   }
}
Narek Saribekyan
snar
New poster
 
Posts: 44
Joined: Thu Sep 01, 2005 12:14 pm
Location: Yerevan, Armenia

Postby arif_pasha » Fri May 12, 2006 8:04 pm

Try this input:
Code: Select all
8
0 0
.5 0
1 0
1 .5
1 1
.5 1
0 1
0 .5
0


My Accepted code give this output:
Code: Select all
Region #1:
(0.0,1.0) - (0.5,1.0) - (1.0,1.0) - (1.0,0.5) - (1.0,0.0) - (0.5,0.0) - (0.0,0.0) - (0.0,1.0)
Perimeter length = 4.00

hope it helps
arif_pasha
New poster
 
Posts: 42
Joined: Fri Jun 13, 2003 3:47 pm
Location: Dhaka , Bangladesh

Postby snar » Sat May 13, 2006 8:17 pm

OK,
I'll let you know about results.
Narek Saribekyan
snar
New poster
 
Posts: 44
Joined: Thu Sep 01, 2005 12:14 pm
Location: Yerevan, Armenia

Postby Moha » Sat May 13, 2006 8:40 pm

Moha
Experienced poster
 
Posts: 216
Joined: Tue Aug 31, 2004 1:02 am
Location: Tehran

Postby snar » Sat May 13, 2006 8:52 pm

Thanks,
I'll try them too, when i'll have a time.
Narek Saribekyan
snar
New poster
 
Posts: 44
Joined: Thu Sep 01, 2005 12:14 pm
Location: Yerevan, Armenia

Postby snar » Sun May 14, 2006 6:54 pm

Got it!

My algorithm was building a Convex Hull with minimal number of vertices. I've changed it to maximum ( including colliear points too ) and got Accepted.

Thanks everyone,
Narek Saribekyan
snar
New poster
 
Posts: 44
Joined: Thu Sep 01, 2005 12:14 pm
Location: Yerevan, Armenia

Postby Moha » Mon May 15, 2006 1:45 pm

Yes, as the problem statement says that.
Moha
Experienced poster
 
Posts: 216
Joined: Tue Aug 31, 2004 1:02 am
Location: Tehran

Re: 218 - WA

Postby Gourav.in » Sat May 28, 2011 10:45 pm

shouldnt the output of this input
Code: Select all
8
0 0
.5 0
1 0
1 .5
1 1
.5 1
0 1
0 .5
0

output
Code: Select all
Region #1:
(0.0,0.5)-(0.0,1.0)-(0.5,1.0)-(1.0,1.0)-(1.0,0.5)-(1.0,0.0)-(0.5,0.0)-(0.0,0.0)-(0.0,0.5)
Perimeter length = 4.00


plzz help ??
Gourav.in
New poster
 
Posts: 4
Joined: Sat May 28, 2011 10:40 pm

Re: 218 - WA

Postby Gourav.in » Mon May 30, 2011 3:12 am

Got it accpeted :D

the ouput should be
Code: Select all
Region #1:
(0.0,0.5)-(0.0,1.0)-(0.5,1.0)-(1.0,1.0)-(1.0,0.5)-(1.0,0.0)-(0.5,0.0)-(0.0,0.0)-(0.0,0.5)
Perimeter length = 4.00
Gourav.in
New poster
 
Posts: 4
Joined: Sat May 28, 2011 10:40 pm


Return to Volume II

Who is online

Users browsing this forum: No registered users and 1 guest