Techno Blender
Digitally Yours.

Find line which does not intersect with parabola

0 58


#include <bits/stdc++.h>

using namespace std;

  

struct Parabola {

    int a, b, c;

};

  

void findLine(int lines[], Parabola parabolas[], int n,

              int m)

{

  

    sort(lines, lines + n);

  

    for (int i = 0; i < m; i++) {

        int a, b, c;

        a = parabolas[i].a;

        b = parabolas[i].b;

        c = parabolas[i].c;

  

        int ind = lower_bound(lines, lines + n, b) - lines;

        if (ind < n

            && (lines[ind] - b) * (lines[ind] - b)

                   < 4 * a * c) {

            cout << "YES " << lines[ind] << "\n";

            continue;

        }

        if (ind > 0

            && (lines[ind - 1] - b) * (lines[ind - 1] - b)

                   < 4 * a * c) {

            cout << "YES " << lines[ind - 1] << "\n";

            continue;

        }

        cout << "NO\n";

    }

}

  

int main()

{

    int n = 2, m = 3;

    int lines[] = { 0, 2 };

    Parabola parabolas[]

        = { { 2, 2, 1 }, { 1, -2, 1 }, { 1, -2, -1 } };

  

    

    findLine(lines, parabolas, n, m);

  

    return 0;

}


#include <bits/stdc++.h>

using namespace std;

  

struct Parabola {

    int a, b, c;

};

  

void findLine(int lines[], Parabola parabolas[], int n,

              int m)

{

  

    sort(lines, lines + n);

  

    for (int i = 0; i < m; i++) {

        int a, b, c;

        a = parabolas[i].a;

        b = parabolas[i].b;

        c = parabolas[i].c;

  

        int ind = lower_bound(lines, lines + n, b) - lines;

        if (ind < n

            && (lines[ind] - b) * (lines[ind] - b)

                   < 4 * a * c) {

            cout << "YES " << lines[ind] << "\n";

            continue;

        }

        if (ind > 0

            && (lines[ind - 1] - b) * (lines[ind - 1] - b)

                   < 4 * a * c) {

            cout << "YES " << lines[ind - 1] << "\n";

            continue;

        }

        cout << "NO\n";

    }

}

  

int main()

{

    int n = 2, m = 3;

    int lines[] = { 0, 2 };

    Parabola parabolas[]

        = { { 2, 2, 1 }, { 1, -2, 1 }, { 1, -2, -1 } };

  

    

    findLine(lines, parabolas, n, m);

  

    return 0;

}

FOLLOW US ON GOOGLE NEWS

Read original article here

Denial of responsibility! Techno Blender is an automatic aggregator of the all world’s media. In each content, the hyperlink to the primary source is specified. All trademarks belong to their rightful owners, all materials to their authors. If you are the owner of the content and do not want us to publish your materials, please contact us by email – [email protected]. The content will be deleted within 24 hours.

Leave a comment