zoukankan      html  css  js  c++  java
  • #421(div2)B. Mister B and Angle in Polygon

    On one quiet day all of sudden Mister B decided to draw angle a on his field. Aliens have already visited his field and left many different geometric figures on it. One of the figures is regular convex n-gon (regular convex polygon with n sides).

    That's why Mister B decided to use this polygon. Now Mister B must find three distinct vertices v1, v2, v3 such that the angle (where v2 is the vertex of the angle, and v1 and v3 lie on its sides) is as close as possible to a. In other words, the value should be minimum possible.

    If there are many optimal solutions, Mister B should be satisfied with any of them.

    Input

    First and only line contains two space-separated integers n and a (3 ≤ n ≤ 105, 1 ≤ a ≤ 180) — the number of vertices in the polygon and the needed angle, in degrees.

    Output

    Print three space-separated integers: the vertices v1, v2, v3, which form . If there are multiple optimal solutions, print any of them. The vertices are numbered from 1 to n in clockwise order.

    Examples
    Input
    3 15
    Output
    1 2 3
    Input
    4 67
    Output
    2 1 3
    Input
    4 68
    Output
    4 1 2
    Note

    In first sample test vertices of regular triangle can create only angle of 60 degrees, that's why every possible angle is correct.

    Vertices of square can create 45 or 90 degrees angles only. That's why in second sample test the angle of 45 degrees was chosen, since |45 - 67| < |90 - 67|. Other correct answers are: "3 1 2", "3 2 4", "4 2 3", "4 3 1", "1 3 4", "1 4 2", "2 4 1", "4 1 3", "3 1 4", "3 4 2", "2 4 3", "2 3 1", "1 3 2", "1 2 4", "4 2 1".

    In third sample test, on the contrary, the angle of 90 degrees was chosen, since |90 - 68| < |45 - 68|. Other correct answers are: "2 1 4", "3 2 1", "1 2 3", "4 3 2", "2 3 4", "1 4 3", "3 4 1".

    题意:给出N,X,问正N边形,我们找出三个点,使其组成的角度最接近X,点的编号按照顺时针增加

    思路:正多边形,我们可以知道三个点组成的角度只有N-2个,我们可以求出最小的那个角度即2 1 3,第二小的为2 1 4 ,最大的为  2  1  N

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 
     4 int main(){
     5    int n,x;
     6    cin>>n>>x;
     7    double sum=(n-2)*180*1.0;
     8    double s1=sum/n*1.0;
     9    int xx=n-2;
    10    double  MMin=s1/xx*1.0;
    11    double Min=1e9;
    12    int k;
    13    for(int i=1;i<=n-2;i++){
    14         double y=abs(MMin*i-x)*1.0;
    15         if(y<Min){
    16             Min=y;
    17             k=i;
    18         }
    19    }
    20    cout<<2<<" "<<1<<" "<<2+k<<endl;
    21 }
  • 相关阅读:
    分页查询SQL语句
    屏蔽Ctrl+C
    RichtextBox 控件小节
    必须掌握的八个CMD命令
    [唠叨两句]一个关于OpenFileDialog 影响 相对路径的问题
    反序列化出现异常:SerializationException 在分析完成之前就遇到流结尾
    Static块(静态代码块)
    Java ServletContext 详解
    tomcat中conf\Catalina\localhost目录下的J2EE项目METAINF配置文件
    关于【apache tomcat 5.5.15/conf /Catalina/localhost配置虚拟目录】时的一些问题。(配置web项目的方式不止一种,虚拟目录就是一个)
  • 原文地址:https://www.cnblogs.com/hhxj/p/7090240.html
Copyright © 2011-2022 走看看