📜  满足点(A,B)和方程式时的抛物线

📅  最后修改于: 2021-05-04 07:31:41             🧑  作者: Mango

给定一个点(A,B) ,使得曲线上每个点的距离My = Nx 2 + Ox + P (A,B)等于曲线上该点与x轴之间的距离。任务是找到M,NO和P的值。

注意:该方程式应为简单形式,即gcd(| M |,| N |,| O |,| P |)= 1N始终为正。

例子:

方法:从抛物线的属性来看,对于曲线上的每个点,其与准线和焦点的距离将始终相等。使用此属性,将y = 0当作一个准线,将(A,B)当作焦点。
由于方程中N始终为正,因此抛物线将朝上,抛物线的方程为(x – h) 2 = 4p(y – k) ,其中(h,k)是顶点和p是焦点和顶点或顶点和方向之间的距离。

由于顶点是形成焦点(A,B)的垂直距离和此处的方向(A,0)之间的中点,因此为B。因此,顶点的坐标为(A,B / 2),并且p也是B / 2
因此,等式为(x – A) 2 = 4 * B / 2 *(y – B / 2)
可以求解此方程式以得出结果:

下面是上述方法的实现:

C++
// C++ implementation of the approach
#include 
using namespace std;
 
// Function to find the required values
void solve(int A, int B)
{
    double p = B / 2.0;
    int M = ceil(4 * p);
    int N = 1;
    int O = - 2 * A;
    int Q = ceil(A * A + 4 * p*p);
    cout << M << " " << N << " "
         << O << " " << Q;
}
 
// Driver code
int main()
{
    int a = 1;
    int b = 1;
    solve(a, b);
}
 
// This code is contributed by Mohit Kumar


Java
// Java implementation of the approach
class GFG
{
     
    // Function to find the required values
    static void solve(int A, int B)
    {
        double p = B / 2.0;
        double M = Math.ceil(4 * p);
        int N = 1;
        int O = - 2 * A;
        double Q = Math.ceil(A * A + 4 * p * p);
        System.out.println(M + " " + N +
                               " " + O + " " + Q);
    }
     
    // Driver code
    public static void main (String[] args)
    {
        int a = 1;
        int b = 1;
        solve(a, b);
    }
}
 
// This code is contributed by AnkitRai01


Python3
# Python3 implementation of the approach
 
# Function to find the required values
def solve(A, B):
    p = B / 2
    M = int(4 * p)
    N = 1
    O = - 2 * A
    Q = int(A * A + 4 * p*p)
    return [M, N, O, Q]
 
# Driver code
a = 1
b = 1
print(*solve(a, b))


C#
// C# implementation of the approach
using System;
 
class GFG
{
    // Function to find the required values
    static void solve(int A, int B)
    {
        double p = B / 2.0;
         
        double M = Math.Ceiling(4 * p);
         
        int N = 1;
        int O = - 2 * A;
         
        double Q = Math.Ceiling(A * A + 4 * p * p);
         
        Console.Write(M + " " + N + " " + O + " " + Q);
    }
     
    // Driver code
    static public void Main ()
    {
        int a = 1;
        int b = 1;
        solve(a, b);
    }
}
 
// This code is contributed by AnkitRai01


输出:
2 1 -2 2