c++ compiler problems

The forum to report every bug you find or tell us what you'd like to find in UVa OJ

Moderator: Board moderators

Locked
shadow
New poster
Posts: 3
Joined: Mon Jan 16, 2006 10:33 pm

c++ compiler problems

Post by shadow »

the c++ compiler cant compile the program below, it just responds as "Recieved", and sometimes compile error. whats the problem?

#define NDEBUG

#include <cstdio>
#include <cassert>
#include <iostream>
#include <complex>
#include <cmath>
using namespace std;

typedef complex<int> point, vect;
typedef long long int64;

int64 Cross(const vect &u, const vect &v)
{
return (conj(u) * v).imag();
}

bool onseg(const point &P, const point seg[2])
{
return (P.real() >= min(seg[0].real(), seg[1].real()) &&
P.real() <= max(seg[0].real(), seg[1].real()) &&
P.imag() >= min(seg[0].imag(), seg[1].imag()) &&
P.imag() <= max(seg[0].imag(), seg[1].imag()));
}

int sgnll(int64 x)
{
if (x > 0)
return 1;
if (x < 0)
return -1;
return 0;
}

bool intersect(const point seg[2][2])
{
bool nepi = true; /* non endpoint intersection */
for (int i = 0; i < 2; ++i)
{
int64 dir[2];
for (int j = 0; j < 2; ++j)
{
dir[j] = Cross(seg[!i][0] - seg[j], seg[!i][1] - seg[j]);
if (dir[j] == 0 && onseg(seg[j], seg[!i]))
return true;
}
int s[2] = {sgnll(dir[0]), sgnll(dir[1])};
nepi &= (s[0] == 1 && s[1] == -1) || (s[0] == -1 && s[1] == 1);
}
return nepi; /* no epi's left to concern about */
}

point getp()
{
int x, y;
scanf("%d %d", &x, &y);
return point(x, y);
}

int main()
{
int ntc;
scanf("%d", &ntc);
for (int tc = 0; tc < ntc; ++tc)
{
point P[2] = {getp(), getp()}, R[2][2] = {{getp(), getp()}};

for (int k = 0; k < 2; ++k)
R[1][k] = point(R[0][k].real(), R[0][!k].imag());

/* for (int i = 0; i < 2; ++i)
for (int j = 0; j < 2; ++j)
cerr << "R[" << i << "][" << j << "]: " << R[j] << endl;*/

bool res = false;
for (int k = 0; k < 2; ++k)
{
res |= onseg(P[k], R[0]);
const point seg[2][2] = {{P[0], P[1]}, {R[k][0], R[k][1]}};
res |= intersect(seg);
}

if (res)
printf("T\n");
else
printf("F\n");
}

return 0;
}
chunyi81
A great helper
Posts: 293
Joined: Sat Jun 21, 2003 4:19 am
Location: Singapore

Post by chunyi81 »

What compiler are you using?

I got the following errors when I compiled with g++ 2.95.3:

Code: Select all

testing.cpp: In function `bool onseg(const point &, const complex<int> *)':
testing.cpp:20: implicit declaration of function `int min(...)'
testing.cpp:21: implicit declaration of function `int max(...)'
testing.cpp: In function `int main()':
testing.cpp:79: conversion from `const complex<int>[2]' to non-scalar type `complex<int>' requested
testing.cpp:79: conversion from `const complex<int>[2]' to non-scalar type `complex<int>' requested
min and max are defined in the algorithm library. You have to include all the libraries you used in your program explicitly as the compiler in this OJ does not do it for you.

Also this line of code is causing some weird compile error:

Code: Select all

const point seg[2][2] = {{P[0], P[1]}, {R[k][0], R[k][1]}}; 
Remove the const qualifier to correct this error, although this does not make any sense since your intersection function takes in a const complex<int>. I am not sure why this is happening. Can any C/C++ expert explain?
shadow
New poster
Posts: 3
Joined: Mon Jan 16, 2006 10:33 pm

Post by shadow »

thanks. it compiled.
I use g++ 3.3.3, But I didnt get any on those errors on my compiler.
How does the online-judge compiler detect all headers needed?
Can I compile that way on my PC?
Carlos
System administrator
Posts: 1286
Joined: Sat Oct 13, 2001 2:00 am
Location: Valladolid, Spain
Contact:

Post by Carlos »

OJ doesn't detect what headers to use, it just includes the headers you include explicitely.

As this problem is solved, and I don't knkow the exact compile command (i should dig into the source to get that> too troublesome) I close this topic.
DON'T PM ME --> For any doubt, suggestion or error reporting, please use the "Contact us" form in the web.
Locked

Return to “Bugs and suggestions”