zoukankan      html  css  js  c++  java
  • HDU 5660 jrMz and angles (暴力枚举)

    jrMz and angles

    题目链接:

    http://acm.hust.edu.cn/vjudge/contest/123316#problem/E

    Description

    jrMz has two types of angles, one type of angle is an interior angle of -sided regular polygon, and the other type of angle is an interior angle of -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 ——The number of the test cases.
    For each test case, the only line contains two integers 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.

    题意:

    给出m和n; 对于正m边形和正n边形;
    任取这两个几何图形的内角;(可取超过m个正m边形的内角)
    判断能否使其之和为360度.

    题解:

    公式:正N边形的内角度数为 (N-2) * 180° / N ;
    由于n和m的规模较小,直接枚举即可;
    注意:

    1. 讲道理对于正n边形,不会取到超过n个内角(n越大内角越大);
      但是n=3时为特例,可以取6个60°构成360度;
      可以对n=3特判或者枚举时扩大范围至n+3;
    2. 题目给的n m范围为大于等于1,一开始很疑惑1和2的时候怎么处理;
      后来直接交了后发现没有这种测试数据...

    代码:

    代码1:化简了一通;i(n-2)180/n + j(m-2)180/m = 360;

    化简后为 i(n-2)m + j(m-2)n == 2mn;

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    #include <queue>
    #include <map>
    #include <set>
    #include <vector>
    #define LL long long
    #define eps 1e-8
    #define maxn 1500
    #define mod 100000007
    #define inf 0x3f3f3f3f
    #define IN freopen("in.txt","r",stdin);
    using namespace std;
    
    
    int main(int argc, char const *argv[])
    {
        //IN;
    
        int t;  scanf("%d", &t);
        while(t--)
        {
            cin >> n >> m;
            int a = (n-2)*m;
            int b = (m-2)*n;
            int c = 2*m*n;
    
            int flag = 0;
            for(int i=0; i<=n+3; i++) {
                for(int j=0; j<=m+3; j++) {
                    if(a*i+b*j==c) {flag = 1;break;}
                }
                if(flag) break;
            }
    
            if(flag) printf("Yes
    ");
            else printf("No
    ");
        }
    
        return 0;
    }
    

    代码2:直接先算出每个内角度数再枚举.

    (double改成int也过了,很奇怪)

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    #include <queue>
    #include <map>
    #include <set>
    #include <vector>
    #define LL long long
    #define eps 1e-8
    #define maxn 1100
    #define inf 0x3f3f3f3f
    #define IN freopen("in.txt","r",stdin);
    using namespace std;
    
    int n, m;
    
    int main(int argc, char const *argv[])
    {
        //IN;
    
        int t;  scanf("%d", &t);
        while(t--)
        {
            scanf("%d %d", &n, &m);
    
            double a = (n-2)*180/n;
            double b = (m-2)*180/m;
    
            int flag = 0;
            for(int i=0; ; i++) {
                if(a*i > 360.0) break;
                for(int j=0; ; j++) {
                    if(a*i+b*j == 360.0) {
                        flag = 1;
                        break;
                    }
                    if(a*i+b*j > 360.0) break;
                }
                if(flag) break;
            }
    
            if(flag) printf("Yes
    ");
            else printf("No
    ");
        }
    
        return 0;
    }
    
    
  • 相关阅读:
    103、服务器出现大量close_wait的连接的原因是什么?有什么解决方法?
    102、常见的HTTP状态码有哪些?
    rpm包管理、yum源及创建本地仓库(同步华为源)
    文件管理之:输出与重定向echo
    高级权限--acl, mask,文件属性权限;su切换用户,sudo提权
    基本权限;权限对⽂件or⽬录的意义;特殊权限;文件权限之umask
    权限管理--用户介绍;用户与组相关文件;用户管理命令之用户创建、查看、删除、修改
    文件管理之:打包、压缩
    字符处理命令-sort排序,uniq去重,cut剪切文件,tr删除或替换结果集,wc统计
    上传与下载wget、curl、r z、s z
  • 原文地址:https://www.cnblogs.com/Sunshine-tcf/p/5698875.html
Copyright © 2011-2022 走看看