hduoj-5660【思维】
来源:互联网 发布:二手网络通讯设备回收 编辑:程序博客网 时间:2024/06/16 08:31
题目链接:点击打开链接
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(1≤T≤10) ——The number of the test cases.
For each test case, the only line contains two integersn,m(1≤n,m≤100) with a white space separated.
For each test case, the only line contains two integers
Output
For each test case, the only line contains a integer that is the answer.
Sample Input
34 83 105 8
Sample Output
YesYesNoHintIn 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有两种角,第一种角都是正n边形的内角,第二种角都是正m边形的内角。jrMz想选出其中一些,某种角可以选多个或一个都不选,使得选出的所有角的度数之和恰好为360度。jrMz想知道这是否可能实现。
输入描述
有多组测试数据,第一行一个整数(1≤T≤10),表示测试数据的组数。对于每组测试数据,仅一行,两个整数n,m(3≤n,m≤100),之间有一个空格隔开。
输出描述
对于每组测试数据,仅一行,一个字符串,若可能实现则为Yes,若不可能实现则为No。
输入样例
34 83 105 8
输出样例
YesYesNo
Hint
第一组数据中,jrMz可以选择1个第一种角和2个第二种角,因为90+135+135=360。第二组数据中,jrMz可以选择6个第一种角,因为6×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
- hduoj-5660【思维】
- hduoj 1432 Lining Up【思维】
- HDUOJ
- HDUoj
- HDUOJ 2050
- HDUOJ 2018
- HDUOJ 2069
- HDUOJ 1303
- HDUOJ 2031
- HDUOJ 2047
- HDUOJ 2089
- hduoj 1708
- hduoj 2031
- hduoj 2032
- hduoj 1062
- HDUOJ 1039
- HDUOJ lines
- HDUOJ入门
- 小白们应该知道,在Eclipse当中怎样在编译页面当中显示行号.
- vb:Cg色彩精灵 附表:主要控件及属性说明表
- 封装获取网络图片并改变尺寸
- JAVA——BigInteger
- springmvc+hibernate+maven+ajax+分页的整合
- hduoj-5660【思维】
- Windows系统中cmd命令总结
- openrule
- 【J2EE】javabean
- Java中LinkedList的使用
- Leetcode155——Min Stack
- 《ACM程序设计》书中题目K 第十一题 堆墙
- Ubuntu14.04下载编译Android6.0源码
- ubuntu/win7下设置win7为第一启动项