Hello 2019 B Petr and a Combination Lock

本文探讨了一个有趣的数学问题,即如何通过一系列顺时针或逆时针旋转使组合锁的指针回到初始位置。通过二进制枚举的方法,我们实现了暴力求解,最终判断是否至少存在一种旋转方式使得指针能准确对准零刻度。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

                                                       B. Petr and a Combination Lock

time limit per test  1 second    memory limit per test   256 megabytes

input  standard input

output   standard output

Petr has just bought a new car. He's just arrived at the most known Petersburg's petrol station to refuel it when he suddenly discovered that the petrol tank is secured with a combination lock! The lock has a scale of 360

degrees and a pointer which initially points at zero:

Petr called his car dealer, who instructed him to rotate the lock's wheel exactly n

times. The i-th rotation should be ai degrees, either clockwise or counterclockwise, and after all n

rotations the pointer should again point at zero.

This confused Petr a little bit as he isn't sure which rotations should be done clockwise and which should be done counterclockwise. As there are many possible ways of rotating the lock, help him and find out whether there exists at least one, such that after all n

rotations the pointer will point at zero again.

Input

The first line contains one integer n (1≤n≤15) — the number of rotations. Each of the following n lines contains one integer ai (1≤ai≤180) — the angle of the i-th rotation in degrees.

Output

If it is possible to do all the rotations so that the pointer will point at zero after all of them are performed, print a single word "YES". Otherwise, print "NO". Petr will probably buy a new car in this case.

You can print each letter in any case (upper or lower).

Examples

Input

Copy

3
10
20
30

Output

Copy

YES

Input

Copy

3
10
10
10

Output

Copy

NO

Input

Copy

3
120
120
120

Output

Copy

YES

Note

In the first example, we can achieve our goal by applying the first and the second rotation clockwise, and performing the third rotation counterclockwise.

In the second example, it's impossible to perform the rotations in order to make the pointer point at zero in the end.

In the third example, Petr can do all three rotations clockwise. In this case, the whole wheel will be rotated by 360

degrees clockwise and the pointer will point at zero again.

///////////////////////////////////////////////////////////////////////////////////////////////////

解法很多 我这里是二进制枚举(嗯,暴力) 注意下咋枚举就行,详见代码

#include<cstdio>
#include<cstring>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<stdlib.h>
using namespace std;
const int inf=0x3f3f3f3f;
const int maxn=1000000; 
int a[maxn];
int main(){ 
    int n;
    cin>>n; 
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int flag=0;
    int ans=0;
    for(int i=0;i<1<<n;i++){//共有1<<n个状态 枚举每个状态 
        ans=0;
        for(int j=0;j<n;j++){//枚举每个状态的每一位  如1111 
            if(i&(1<<j)){//这里是 1  就相加(顺时针) 
                ans+=a[j];
                ans=ans%360;
            }else{  // 0  就想减(逆时针) 
                ans-=a[j];
                ans=ans%360;
            }
        }
        if(ans==0){//即转了一圈 
            flag=1;
            break;
        }
    }
    if(flag){
        cout<<"YES";
    }else{
        printf("NO");
    }
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值