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\times60=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\n");
else printf("No\n");
} 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\n");
else printf("No\n");
} return 0;
}

HDU 5660 jrMz and angles (暴力枚举)的更多相关文章

  1. hdu 1172 猜数字(暴力枚举)

    题目 这是一道可以暴力枚举的水题. //以下两个都可以ac,其实差不多一样,呵呵 //1: //4 wei shu #include<stdio.h> struct tt { ],b[], ...

  2. hdu 4445 Crazy Tank (暴力枚举)

    Crazy Tank Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  3. HDU 4770 Lights Against Dudely 暴力枚举+dfs

    又一发吐血ac,,,再次明白了用函数(代码重用)和思路清晰的重要性. 11779687 2014-10-02 20:57:53 Accepted 4770 0MS 496K 2976 B G++ cz ...

  4. HDU 4930 Fighting the Landlords(暴力枚举+模拟)

    HDU 4930 Fighting the Landlords 题目链接 题意:就是题中那几种牌型.假设先手能一步走完.或者一步让后手无法管上,就赢 思路:先枚举出两个人全部可能的牌型的最大值.然后再 ...

  5. HDU 4431 Mahjong (DFS,暴力枚举,剪枝)

    题意:给定 13 张麻将牌,问你是不是“听”牌,如果是输出“听”哪张. 析:这个题,很明显的暴力,就是在原来的基础上再放上一张牌,看看是不是能胡,想法很简单,也比较好实现,结果就是TLE,一直TLE, ...

  6. HDU 1270 小希的数表 (暴力枚举+数学)

    题意:... 析:我们可以知道,a1+a2=b1,那么我们可以枚举a1,那么a2就有了,并且a1+a3=b2,所以a3就有了,我们再从把里面的剩下的数两两相加,并从b数组中去掉, 那么剩下的最小的就是 ...

  7. hdu 5491 The Next(暴力枚举)

    Problem Description Let L denote the number of 1s in integer D’s binary representation. Given two in ...

  8. HDU 4462 Scaring the Birds (暴力枚举DFS)

    题目链接:pid=4462">传送门 题意:一个n*n的区域,有m个位置是能够放稻草人的.其余都是玉米.对于每一个位置(x,y)所放稻草人都有个作用范围ri, 即abs(x-i)+ab ...

  9. HDU 6351暴力枚举 6354计算几何

    Beautiful Now Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)T ...

随机推荐

  1. NDK(19)简单示例:ndk调用java基本方法、数组;使用stl、访问设备

    一.ndk调用java类示例 1,调用基本方法 /* * Class: com_example_ndksample_MainActivity * Method: ndkFindJavaClass * ...

  2. word编辑器解码集合

    $(document).ready(function () { $(".content").each(function () { var content = $(this).htm ...

  3. POJ 3687 Labeling Balls【拓扑排序 优先队列】

    题意:给出n个人,m个轻重关系,求满足给出的轻重关系的并且满足编号小的尽量在前面的序列 因为输入的是a比b重,但是我们要找的是更轻的,所以需要逆向建图 逆向建图参看的这一篇http://blog.cs ...

  4. POJ 1088 滑雪【记忆化搜索】

    题意:给出一个二维矩阵,要求从其中的一点出发,并且当前点的值总是比下一点的值大,求最长路径 记忆化搜索,首先将d数组初始化为0,该点能够到达的路径长度保存在d数组中,同时把因为路径是非负的,所以如果已 ...

  5. poj 1742 Coins

    // v给出N种硬币和个数,问可以取到1->M中的多少个值.// 背包 完全背包 或多 重背包(二进制优化)都可以做// #include <iostream> #include & ...

  6. 【JS】<c:foreach>用法

    <c:foreach>类似于for和foreach循环   以下是我目前见过的用法: 1.循环遍历,输出所有的元素. <c:foreach items="${list}&q ...

  7. 【转】TLB(Translation Lookaside Buffers,TLB)的作用

    原文网址:http://sdnydubing.blog.163.com/blog/static/137470570201122810503396/ 从虚拟地址到物理地址的转换过程可知:使用一级页表进行 ...

  8. solr4.5配置中文分词器mmseg4j

    solr4.x虽然提供了分词器,但不太适合对中文的分词,给大家推荐一个中文分词器mmseg4j mmseg4j的下载地址:https://code.google.com/p/mmseg4j/ 通过以下 ...

  9. Android 的实现TextView中文字链接的4种方法

    Android 的实现TextView中文字链接的方式有很多种. 总结起来大概有4种: 1.当文字中出现URL.E-mail.电话号码等的时候,可以将TextView的android:autoLink ...

  10. bjfu1235 两圆公共面积

    给定两个圆,求其覆盖的面积,其实也就是求其公共面积(然后用两圆面积和减去此值即得最后结果). 我一开始是用计算几何的方法做的,结果始终不过.代码如下: /* * Author : ben */ #in ...