Codeforces Round #165 (Div. 2)A. Fancy Fence

A. Fancy Fence

time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.

He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle a.

Will the robot be able to build the fence Emuskald wants? In other words, is there a regular polygon which angles are equal to a?

翻译:
埃姆斯卡尔德需要在他的农场周围建一道栅栏,但他懒得自己建篱笆。于是他买了一个筑篱笆的机器人。

他希望栅栏是一个普通的多边形。机器人沿着一条小路建造栅栏,但它只能使栅栏角在一个角度。

机器人能建造埃姆斯卡尔德想要的栅栏吗?换句话说,是否有一个常规的多边形,其角度等于 a?

Input

The first line of input contains an integer t (0 < t < 180) — the number of tests. Each of the following t lines contains a single integer a (0 < a < 180) — the angle the robot can make corners at measured in degrees.

翻译:
第一行输入包含整数t(0<t<180)-测试数量。 以下每条t行都包含一个整数 a(0 < a < 180) — — 机器人可以以度度测量角的角度。

Output

For each test, output on a single line “YES” (without quotes), if the robot can build a fence Emuskald wants, and “NO” (without quotes), if it is impossible.

翻译:
对于每个测试,如果机器人可以建立一个围栏Emuskald想要,输出在一行"YES"(没有引号)和如果它是不可能的,输出"NO"(没有引号)。

Examples

inputCopy

扫描二维码关注公众号,回复: 12611600 查看本文章
3
30
60
90

outputCopy

NO
YES
YES

Note
In the first test case, it is impossible to build the fence, since there is no regular polygon with angle .

In the second test case, the fence is a regular triangle, and in the last test case — a square.

解题思路

1、首先理解概念,正多边形就是各边相等,各角相等的多边形;
2、重要公式:一个顶角 * 边数 = 180 * (边数-2);
3、要形成正多边形边数至少要有3条,当边数是 3 的时候,sum<should 了,这个时候绝不可能形成正多边形,随着边数的增加,两者之间的差距会越来越大。为什么,因为要形成正多边形她的一个顶角角度永远不可能达到180,相乘之后,差距就会越来越大
4、只有当 sum<should 的时候,慢慢增加边数,他们之间的距离开始变小,无法达到相等,反而大了,就跳出循环。
在这里插入图片描述

参考代码

#include<iostream>
#include<algorithm>
using namespace std;

int main()
{
    
    
	int t,x;
	cin>>t;
	while(t--){
    
    
		cin>>x;
		int flag=0;//做标记
		int sum,should,i=3;// i用来代表边数,多边形边数至少要有3条
		sum=1;
		should=0;
		while(sum>should){
    
    
			sum=x*i;
			should=180*(i-2);
			if(sum==should){
    
     //当内角和能达到正确的多边形的角度时,就标记并退出
				flag=1;
				break;
			}
			i++;	
		}
		if(flag)
			cout<<"YES";
		else
			cout<<"NO";
		cout<<endl;
	}
	return 0;
}

没明白的话,欢迎来打扰;
学会了的话,留下一个赞,互相鼓励哦!!!

猜你喜欢

转载自blog.csdn.net/weixin_45950429/article/details/113906128