Why WA? Please help me... i mad with this problem...

Code: Select all

```
/* ACM Problem Set */
/* Problem 143 */
/* Orchard Trees */
#include <cstdio>
#include <math.h>
#include <stdlib.h>
#define min(a,b) a < b ? a : b
#define max(a,b) a > b ? a : b
#define less0(a) a < 1 ? 1 : a
#define most100(a) a > 99 ? 99 : a
#define epsilon 0.00000001
using namespace std;
bool IsIntersectWithHorizont (int H, long double x1, long double y1, long double x2, long double y2)
{
if (y1 == y2) return false;
long double X = x2 - ((y2 - (long double)H) * (x2 - x1) / (y2 - y1));
if (((X >= x1) && (X <= x2)) || ((X <= x1) && (X >= x2))) return true;
else return false;
}
long double FindIntersectWithHorizont (int H, long double x1, long double y1, long double x2, long double y2)
{
return x2 - ((y2 - (long double)H) * (x2 - x1) / (y2 - y1));
}
int CountPointsOnLine (int H, long double x1, long double y1, long double x2, long double y2, long double x3, long double y3)
{
long double LeftPoint = 101, RightPoint = 0;
if (IsIntersectWithHorizont(H, x1, y1, x2, y2))
{
LeftPoint = min (LeftPoint, FindIntersectWithHorizont(H, x1, y1, x2, y2));
RightPoint = max (RightPoint, FindIntersectWithHorizont(H, x1, y1, x2, y2));
}
if (IsIntersectWithHorizont(H, x1, y1, x3, y3))
{
LeftPoint = min (LeftPoint, FindIntersectWithHorizont(H, x1, y1, x3, y3));
RightPoint = max (RightPoint, FindIntersectWithHorizont(H, x1, y1, x3, y3));
}
if (IsIntersectWithHorizont(H, x3, y3, x2, y2))
{
LeftPoint = min (LeftPoint, FindIntersectWithHorizont(H, x3, y3, x2, y2));
RightPoint = max (RightPoint, FindIntersectWithHorizont(H, x3, y3, x2, y2));
}
if (RightPoint > 99) RightPoint = 99.0;
if (RightPoint < 1) return 0;
if (LeftPoint < 1) LeftPoint = 1.0;
if (LeftPoint > 99) return 0;
return (int)(float(RightPoint + epsilon) - ceil(LeftPoint - epsilon) + 1);
}
int main()
{
long double x1, x2, x3, y1, y2, y3;
while (scanf("%llf %llf %llf %llf %llf %llf\n", &x1, &y1, &x2, &y2, &x3, &y3) == 6)
{
if (!(x1 || x2 || x3 || y1 || y2 || y3)) break;
int ans = 0;
if ((y1 == y2) && (y2 == y3))
{
if ((int)float(y1) == (int)ceil(y1)) ans = (most100(less0((int)float(max(x1,(max(x2,x3))) + epsilon))) - most100(less0((int)ceil(min(x1,(min(x2,x3))) - epsilon))));
if ((y1 == 100) || (y1 == 0)) ans = 0;
}
else
{
int B = most100(less0((int)ceil(min(y1,(min(y2,y3))) - epsilon)));
int T = most100(less0((int)float(max(y1,(max(y2,y3))) + epsilon)));
for (int y = B; y <= T; y++)
{
ans += CountPointsOnLine(y, x1, y1, x2, y2, x3, y3);
}
}
printf("%4d\n", ans);
}
}
```