zoukankan      html  css  js  c++  java
  • jrMz and angles(水题)

    jrMz and angles

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
    Total Submission(s): 1071    Accepted Submission(s): 560


    Problem Description
    jrMz has two types of angles, one type of angle is an interior angle of n-sided regular polygon, and the other type of angle is an interior angle of m-sided regular polygon. jrMz wants to use them to make up an angle of 360 degrees, which means, jrMz needs to choose some or none of the angles which belong to the first type and some or none of the angles which belong to the second type so that the sum value of the angles chosen equals 360 degrees. But jrMz doesn’t know whether it is possible, can you help him?
     
    Input
    The first line contains an integer T(1T10)——The number of the test cases.
    For each test case, the only line contains two integers n,m(1n,m100) with a white space separated.
     
    Output
    For each test case, the only line contains a integer that is the answer.
     
    Sample Input
    3 4 8 3 10 5 8
     
    Sample Output
    Yes Yes No
    Hint
    In test case 1, jrMz can choose 1 angle which belongs to the first type and 2 angles which belong to the second type, because 90+135+135=360. In test case 2, jrMz can choose 6 angles which belong to the first type, because6 imes60=360. In test case 3, jrMz can’t make up an angle of 360 degrees.
    题解:给两个正n,m边形,选角度凑成360度,每个角度是(n - 2)*180/n
    代码:
    import java.util.Scanner;
    
    public class Main {
        //(n - 2) * 180/n
        private static Scanner cin;
        static{
            cin = new Scanner(System.in);
        }
        
        static double getAng(int x){
            return (x - 2.0) * 180.0 / x;
        }
        
        static boolean isEqual(double x1, double x2){
            if(Math.abs(x1 - x2) < 1e-15){
                return true;
            }else{
                return false;
            }
        }
        static boolean work(int n, int m){
            double x1 = getAng(n);
            double x2 = getAng(m);
            for(int i = 0; i * x1 <= 360.0; i++){
                for(int j = 0; i * x1 + j * x2 <= 360.0;j++){
                    double temp = i * x1 + j * x2;
                    if(isEqual(temp, 360)){
                        return true;
                    }
                }
            }
            return false;
        }
        public static void main(String[] args) {
            int T;
            T = cin.nextInt();
            while(T-- > 0){
                int n = cin.nextInt();
                int m = cin.nextInt();
                if(work(n, m)){
                    System.out.println("Yes");
                }else{
                    System.out.println("No");
                }
            }
        }
    }
    A. New Year Table
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Gerald is setting the New Year table. The table has the form of a circle; its radius equals R. Gerald invited many guests and is concerned whether the table has enough space for plates for all those guests. Consider all plates to be round and have the same radii that equal r. Each plate must be completely inside the table and must touch the edge of the table. Of course, the plates must not intersect, but they can touch each other. Help Gerald determine whether the table is large enough for n plates.

    Input

    The first line contains three integers nR and r (1 ≤ n ≤ 100, 1 ≤ r, R ≤ 1000) — the number of plates, the radius of the table and the plates' radius.

    Output

    Print "YES" (without the quotes) if it is possible to place n plates on the table by the rules given above. If it is impossible, print "NO".

    Remember, that each plate must touch the edge of the table.

    Examples
    input
    output
    input
    output
    input
    output
    Note

    The possible arrangement of the plates for the first sample is:

     

    题意:

    给定一个大圆的半径 R 以及 n 个小院的半径 r

    问能否把这 n 个小圆贴着大圆边缘放下。

    思路:

    2*PI/(2 * a)就好了;注意精度要加上1e-15

    代码:

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    using namespace std;
    const double PI = acos(-1.0);
    
    int main(){
        int n;
        double R, r;
        while(~scanf("%d%lf%lf", &n, &R, &r)){
            if(n == 1){
                if(R >= r){
                    puts("YES");
                }else{
                    puts("NO");
                }
                continue;
            }
            if(R == r){
                if(n <= 1)
                    puts("YES");
                else
                    puts("NO");
                continue; 
            }
            double a = asin(1.0 * r/(R - r));
            double cnt = 2.0 * PI / (2 * a);
            cnt += 1e-15;
            if(n <= cnt){
                puts("YES");
            }else{
                puts("NO");
            }
        }
        return 0;
    } 
  • 相关阅读:
    [Swift]LeetCode380. 常数时间插入、删除和获取随机元素 | Insert Delete GetRandom O(1)
    [Swift]LeetCode378. 有序矩阵中第K小的元素 | Kth Smallest Element in a Sorted Matrix
    说说心声------ 一些经历
    安装eclipse maven插件m2eclipse No repository found containing
    苹果浏览器实战(三)
    CSDN挑战编程——《绝对值最小》
    高可用技术工具包 High Availability Toolkit
    jstl 标签 循环 序号
    坚向的ViewPager,上下滑动的组件,android上下滑动 VerticalPager
    Php socket数据编码
  • 原文地址:https://www.cnblogs.com/handsomecui/p/6557070.html
Copyright © 2011-2022 走看看