📌  相关文章
📜  在 2 个给定点之间具有 'k' 个等距点的圆中钝角的计数

📅  最后修改于: 2021-10-23 09:00:19             🧑  作者: Mango

给定一个圆,其圆周上有 k 个等距点。圆圈中给出了 2 个点 A 和 B。找出由 /_ACB 形成的所有钝角(大于 90 度的角)的计数,其中 C 可以是圆中除 A 或 B 之外的任何点。
笔记 :
A 和 B 不相等。
A < B。
点数介于 1 和 K 之间(均包含在内)。

例子 :

Input : K = 6, A = 1, B = 3.
Output : 1
Explanation : In the circle with 6 
equidistant points, when C = 2 i.e. 
/_123, we get obtuse angle.

Input : K = 6, A = 1, B = 4.
Output : 0
Explanation : In this circle, there 
is no such C that form an obtuse angle.

可以观察到,如果 A 和 B 之间有相等的元素,则不可能有任何 C 使得 ACB 是钝的。此外,可能的钝角数量是 A 和 B 之间较小的弧。
下面是实现:

C++
// C++ program to count number of obtuse
// angles for given two points.
#include 
using namespace std;
 
int countObtuseAngles(int a, int b, int k)
{
    // There are two arcs connecting a
    // and b. Let us count points on
    // both arcs.
    int c1 = (b - a) - 1;
    int c2 = (k - b) + (a - 1);
 
    // Both arcs have same number of
    // points
    if (c1 == c2)
        return 0;
 
    // Points on smaller arc is answer
    return min(c1, c2);
}
 
// Driver code
int main()
{
    int k = 6, a = 1, b = 3;
    cout << countObtuseAngles(a, b, k);
    return 0;
}


Java
// Java program to count number of obtuse
// angles for given two points
class GFG {
 
    static int countObtuseAngles(int a,
                                 int b, int k)
    {
 
        // There are two arcs connecting a
        // and b. Let us count points on
        // both arcs.
        int c1 = (b - a) - 1;
        int c2 = (k - b) + (a - 1);
 
        // Both arcs have same number of
        // points
        if (c1 == c2)
            return 0;
 
        // Points on smaller arc is answer
        return min(c1, c2);
    }
 
    // Driver Program to test above function
    public static void main(String arg[])
    {
 
        int k = 6, a = 1, b = 3;
        System.out.print(countObtuseAngles(a, b, k));
    }
}
 
// This code is contributed by Anant Agarwal.


Python
# C++ program to count number of obtuse
# angles for given two points.
 
def countObtuseAngles( a, b, k):
    # There are two arcs connecting a
    # and b. Let us count points on
    # both arcs.
    c1 = (b - a) - 1
    c2 = (k - b) + (a - 1)
  
    # Both arcs have same number of
    # points
    if (c1 == c2):
       return 0
      
    # Points on smaller arc is answer
    return min(c1, c2)
  
# Driver code
k, a, b = 6, 1, 3
print countObtuseAngles(a, b, k)
 
# This code is contributed by Sachin Bisht


C#
// C# program to count number of obtuse
// angles for given two points
using System;
 
class GFG {
 
    static int countObtuseAngles(int a,
                           int b, int k)
    {
 
        // There are two arcs connecting
        // a and b. Let us count points
        // on both arcs.
        int c1 = (b - a) - 1;
        int c2 = (k - b) + (a - 1);
 
        // Both arcs have same number
        // of points
        if (c1 == c2)
            return 0;
 
        // Points on smaller arc is
        // answer
        return Math.Min(c1, c2);
    }
 
    // Driver Program to test above
    // function
    public static void Main()
    {
 
        int k = 6, a = 1, b = 3;
         
        Console.WriteLine(
           countObtuseAngles(a, b, k));
    }
}
 
// This code is contributed by vt_m.


PHP


Javascript


输出 :

1

如果您希望与专家一起参加现场课程,请参阅DSA 现场工作专业课程学生竞争性编程现场课程