https://codeforces.com/contest/1097/problem/A

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 360360 degrees and a pointer which initially points at zero:

Petr called his car dealer, who instructed him to rotate the lock's wheel exactly nn times. The ii-th rotation should be aiai degrees, either clockwise or counterclockwise, and after all nn 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 nn rotations the pointer will point at zero again.

Input

The first line contains one integer nn (1≤n≤151≤n≤15) — the number of rotations.

Each of the following nn lines contains one integer aiai (1≤ai≤1801≤ai≤180) — the angle of the ii-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
3
10
20
30
output
YES
input
3
10
10
10
output
NO
input
3
120
120
120
output
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 360360 degrees clockwise and the pointer will point at zero again.

1左移i位, 然后与c按位与。
&当两个操作数对应位都是1,结果才是1.
而1<<i 只有右数第i位是1, 其他都是0.
那么要结果非0, 除非c的第i位也是1.
所以 这个就是判断c的第i位是否为1, 如为1, 那么if成立。 否则if不成立。
PS:这里说的第i位都是从0计数的。

所以此处的意思从1开始遍历全部+1,-1的过程

递推

 /*
Author: LargeDumpling
Email: LargeDumpling@qq.com
Edit History:
2019-01-04 File created.
*/ #include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int MAXN=;
int n,a[MAXN],limit;
int main()
{
bool flag=false;
scanf("%d",&n);
for(int i=;i<n;i++)
scanf("%d",&a[i]);
limit=<<n;
for(int S=;S<limit;S++)
{
int sum=;
for(int i=;i<n;i++)
if((S>>i)&) sum+=a[i];
else sum-=a[i];
if(sum%==)
flag=true;
}
if(flag) puts("YES");
else puts("NO");
fclose(stdin);
fclose(stdout);
return ;
}

递归 dfs

 #include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
//#define DEBUG
#define RI register int
using namespace std;
typedef long long ll;
//typedef __int128 lll;
const int N=+;
const int MOD=1e9+;
const double PI = acos(-1.0);
const double EXP = 1E-;
const int INF = 0x3f3f3f3f;
int t,n,m,k,q,ans;
int a[N];
char str;
void dfs(int c,int x){
if(c>=n){
if(x%==)
ans=;
return;
}
if(ans)
return;
dfs(c+,x+a[c+]);
dfs(c+,x-a[c+]);
}
int main()
{
#ifdef DEBUG
freopen("input.in", "r", stdin);
//freopen("output.out", "w", stdout);
#endif
scanf("%d",&n);
for(int i=;i<=n;i++){
cin>>a[i];
}
dfs(,);
if(ans)
cout << "YES" << endl;
else
cout << "NO" << endl; return ;
}

B.Petr and a Combination Lock的更多相关文章

  1. Petr and a Combination Lock

    Petr has just bought a new car. He's just arrived at the most known Petersburg's petrol station to r ...

  2. CF1097B Petr and a Combination Lock 题解

    Content 有一个锁,它只有指针再次指到 \(0\) 刻度处才可以开锁(起始状态如图所示,一圈 \(360\) 度). 以下给出 \(n\) 个操作及每次转动度数,如果可以通过逆时针或顺时针再次转 ...

  3. Combination Lock

    时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Finally, you come to the interview room. You know that a Micr ...

  4. hihocoder #1058 Combination Lock

    传送门 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Finally, you come to the interview room. You know that a ...

  5. 贪心 Codeforces Round #301 (Div. 2) A. Combination Lock

    题目传送门 /* 贪心水题:累加到目标数字的距离,两头找取最小值 */ #include <cstdio> #include <iostream> #include <a ...

  6. Codeforces Round #301 (Div. 2) A. Combination Lock 暴力

    A. Combination Lock Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/540/p ...

  7. Hiho----微软笔试题《Combination Lock》

    Combination Lock 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Finally, you come to the interview room. You ...

  8. CF #301 A :Combination Lock(简单循环)

    A :Combination Lock 题意就是有一个密码箱,密码是n位数,现在有一个当前箱子上显示密码A和正确密码B,求有A到B一共至少需要滚动几次: 简单循环:

  9. hihocoder-第六十一周 Combination Lock

    题目1 : Combination Lock 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Finally, you come to the interview roo ...

随机推荐

  1. 用C语音编写python的扩展模块,也就是python调c库

    用C语音编写python的扩展模块,也就是python调c库   1.用C语言扩展Python的功能: http://www.ibm.com/developerworks/cn/linux/l-pyt ...

  2. classloader加载class的流程及自定义ClassLoader

    java应用环境中不同的class分别由不同的ClassLoader负责加载.一个jvm中默认的classloader有Bootstrap ClassLoader.Extension ClassLoa ...

  3. Quantitative Startegies for Achieving Alpha(二)

    Chapter 3 The Day-To-Day Drivers Of Stock Market Returns Summary: (1) Earning growth is the primary ...

  4. python-globals()、locals()的使用

    globals() 函数返回一个全局变量的字典,包括所有导入的变量locals() 函数返回一个当前位置的所有局部变量的字典print(globals())print(locals()) global ...

  5. linux运维、架构之路-HAProxy反向代理

    一.HAProxy介绍          专业反向代理,支持双机热备支持虚拟主机,配置简单,拥有非常不错的服务器健康检查功能,当其代理的后端节点出现故障, HAProxy会自动将该服务器摘除,故障恢复 ...

  6. Floyd求解最短路

    Floyd算法适用于求解全源最短路.也就是能够求解任意两点间的最短路径并且是适用于含有负权边的图,但是含有负环则不行了!空间复杂度为O(n2).时间复杂度为O(n3).其具体的原理在百度能够找到很多, ...

  7. [CF938E]Max History题解

    题面 >CF传送门< >洛谷传送门< 解法 显而易见,对于一个数\(a_i\),若果它出现在\(f\)序列中,必定\(a_i\)之前的元素要小于\(a_i\),我们设\(cnt ...

  8. sh_01_hello

    sh_01_hello print("hello python") print("你好世界")

  9. UITabbarController & UITabbar 学习

    最后更新2016-04-06 一. UITabbarController 给UITabbarController 设置viewControllers熟悉时候,超过五个就会有一个 moreNavigat ...

  10. iOS Beta 升级或降级

    https://sspai.com/post/45442 public beta网站上安装profile, 去手机看更新 developer beta, 登录开发者网站, downloads, 下载p ...