📌  相关文章
📜  在两个给定点之间有“ k”个等距点的圆中的钝角数

📅  最后修改于: 2021-04-27 20:40:02             🧑  作者: Mango

给定一个圆周,圆周上有k个等距点。圆中给出了2点A和B。查找由/ _ACB形成的所有钝角(大于90度的角)的计数,其中C可以是圆中除A或B之外的任何点。
笔记 :
A和B不相等。
A 点在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