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 1052. Rabbit Hunt

C++. I've got WA#8, can smbd help?
Posted by Ivashkaization_polzunky 15 Nov 2015 18:01
#include <cstdio>
#include <vector>
#include <math.h>
#include <cstdlib>
#include <algorithm>
using namespace std;
double line_k(double x1, double y1, double x2, double y2)
{
    double k = (y2 - y1)/(x2 - x1);
    return k;
}
double line_b(double x1, double y1, double x2, double y2)
{
    double b = y2 - (y2 - y1) * x2 / (x2 - x1);
    return b;
}
bool is_on_line(double k, double b, double x, double y)
{
    if (y <= x * k + b + 0.01 && y >= x * k + b - 0.01) return true;
    return false;
}
struct point{
    double x,y;
};
int main()
{
    int n, counter = 2, max_zerosx = 0, max_zerosy = 0;
    double x, y, k, b;
    vector <point> koord;
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        scanf("%lf %lf", &x, &y);
        if (x == 0) max_zerosx++;
        if (y == 0) max_zerosy++;
        {
            koord.push_back(point());
            koord[i].x = x;
            koord[i].y = y;
        }
    }
    int maximal = max(max_zerosx, max_zerosy);
    for (int i = 0; i < n; i++)
    {
        for (int j = i + 1; j < n; j++)
        {
            k = line_k(koord[i].x, koord[i].y, koord[j].x, koord[j].y);
            b = line_b(koord[i].x, koord[i].y, koord[j].x, koord[j].y);
            for (int l = j + 1; l < n; l++)
                 if (is_on_line(k, b, koord[l].x, koord[l].y))
                     counter++;
            if (counter > maximal) maximal = counter;
            counter = 2;
        }
    }
    printf("%d", maximal);
    return 0;
}
Re: C++. I've got WA#8, can smbd help?
Posted by itanium 24 Nov 2015 02:58
I got WA#8 too. But my solution uses integers only. What is the test?

Edited by author 24.11.2015 03:27
Re: C++. I've got WA#8, can smbd help?
Posted by ToadMonster 24 Nov 2015 14:16
How do you build lines when both points have the same X?
Would you rather use not y=Ax+b but Ax+By+C=0 line equation?

Also I think your epsilon - 0.01 - is too big. You can to avoid float numbers at all.

Edited by author 24.11.2015 14:17

Edited by author 24.11.2015 14:17
Re: C++. I've got WA#8, can smbd help?
Posted by itanium 26 Nov 2015 00:46
This is not problem. My solution uses only integer values (there is no any epsilon), but it crashes on the same test
Re: C++. I've got WA#8, can smbd help?
Posted by Ivashkaization_polzunky 1 Dec 2015 13:44
Thanks alot, will try this!
Re: C++. I've got WA#8, can smbd help?
Posted by int2k 19 Aug 2024 09:22
I got WA on test 8 because division by 0 when I tried to see if 2 vectors of the same root are collinear via checking ratio of x and y, should've just use multiplication