hduoj-5660【思维】

来源:互联网 发布:二手网络通讯设备回收 编辑:程序博客网 时间:2024/06/16 02:07

题目链接:点击打开链接

jrMz and angles

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


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
34 83 105 8
 

Sample Output
YesYesNo
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\times60=360.In test case 3, jrMz can’t make up an angle of 360 degrees.
 

Source
BestCoder Round #79 (div.2)

大意:

问题描述
jrMz有两种角,第一种角都是正nn边形的内角,第二种角都是正mm边形的内角。jrMz想选出其中一些,某种角可以选多个或一个都不选,使得选出的所有角的度数之和恰好为360度。jrMz想知道这是否可能实现。
输入描述
有多组测试数据,第一行一个整数\left(1\leq T\leq10\right)(1T10),表示测试数据的组数。对于每组测试数据,仅一行,两个整数n,m\left(3\leq n,m\leq100\right)n,m(3n,m100),之间有一个空格隔开。
输出描述
对于每组测试数据,仅一行,一个字符串,若可能实现则为Yes,若不可能实现则为No。
输入样例
34 83 105 8
输出样例
YesYesNo
Hint
第一组数据中,jrMz可以选择1个第一种角和2个第二种角,因为90+135+135=36090+135+135=360。第二组数据中,jrMz可以选择6个第一种角,因为6\times60=3606×60=360。第三组数据中,jrMz无法选出一些度数之和为360度的角。

思路:

首先:求 n 多边形内角和公式:(n-2)*180。

由于 n 大于 3 ,所以角 x 的范围为  60<=x<180,注意到只有当 x 或 x1+x2 为 60、90、120、180、360 时才合法,若 a*x1+b*x2 == 360 那么 a 或 b 最大只能为 2,因为 x 最小为 60,若 a 或 b 大于 2 就超过 360 了。

后来感觉自己的方法的 xjb 过的,就去网上看看有没有好一点的码,结果直接暴力就 ok 啊,我个 zz

#include<cstdio>#include<algorithm>#include<cstring>using namespace std;double n,m;bool judge(double x){    if(x==60.0||x==90.0||x==120.0||x==180.0||x==360.0)        return 1;    return 0;}int main(){    int t;    scanf("%d",&t);    while(t--)    {        scanf("%lf%lf",&n,&m);        double a=(n-2)*180.0/n;        double b=(m-2)*180.0/m;        if(judge(a)||judge(b)||judge(2*a+b)||judge(a+2*b))            puts("Yes");        else            puts("No");    }    return 0;}

#include<cstdio>#include<algorithm>#include<cstring>using namespace std;double n,m;int main(){int t;scanf("%d",&t);while(t--){scanf("%lf%lf",&n,&m);double a=(n-2)*180.0/n;double b=(m-2)*180.0/m;bool flag=0;for(int i=0;i<110;i++){for(int j=0;j<110;j++){if(i*a+j*b==360){flag=1;break;}}}if(flag)puts("Yes");elseputs("No");}return 0;}



0 0