c++ compiler problems
Posted: Sat Apr 08, 2006 8:04 pm
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;
}
#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;
}