ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1185. Wall

Can someone help me!!! My code compiles OK but it gets "Crash( A..._V...)")
Posted by nullman 28 May 2002 17:34
My code is:

#include <iostream.h>
#include <math.h>
#define pi acos(-1)
#define lin(a,b,c) (a.x*b.y-b.x*a.y+c.y*(b.x-a.x)+c.x*(a.y-b.y))
#define eq(a,b) ((a.x==b.x && a.y==b.y)?1:0)

typedef struct {double x; double y;} P;

int n,InUse[110];
double res;
P pArr[110];

double sqr(double x) {
  return x*x;
}

double len(P a, P b) {
  return sqrt(sqr(a.x-b.x)+sqr(a.y-b.y));
}

void FindMaxPoly(void) {
  P tmp;
  int i, j;

  for (i=0,tmp=pArr[0];i<n;i++) {
    if (pArr[i].x>tmp.x) j=i;
    InUse[i]=0;
  }
  tmp=pArr[j]; InUse[j]=1;

  while (1) {
    if (eq(tmp,pArr[0])==0) j=0;
    else j=1;
    for (i=0;i<n;i++)
      if ( eq(pArr[i],pArr[j])==0 &&
           eq(pArr[i],tmp)==0 &&
           lin(tmp,pArr[j],pArr[i]) < 0
         ) j=i;
    if (InUse[j]) break;
    InUse[j]=1; tmp=pArr[j];
  }
}

/* The problem differs of ROPE one in that you have to find out
    is one P in the polygon or not!!!
*/

int main() {
  int i,r;
  P last;

  cin>>n>>r;
  for (i=0;i<n;i++) cin>>pArr[i].x>>pArr[i].y;

  FindMaxPoly();
  pArr[n]=pArr[0]; InUse[n]=1;
  res=2*pi*r;

  i=0;
  while (InUse[i]==0) i++;
  last=pArr[i];
  for (i=0;i<=n;i++)
    if (InUse[i]) {
      res+=len(last,pArr[i]);
      last=pArr[i];
    }
  cout<<floor(res);
  //cin.get(); cin.get();
  return 0;
}
Re: Can someone help me!!! My code compiles OK but it gets "Crash( A..._V...)")
Posted by purplefish 28 May 2002 17:44
The code works on my MSVC compiler.