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. USB-TTL

  2. python-第三方包的安装和升级和卸载

    安装源: 豆瓣   http://pypi.douban.com/simple/ 本地安装: egg文件:  使用settools自带的安装脚本easy_install进行安装 whl文件:      ...

  3. 【NOIP2016提高A组模拟8.14】传送带

    题目 在一个2维平面上有两条传送带,每一条传送带可以看成是一条线段.两条传送带分别为线段AB和线段CD.FTD在AB上的移动速度为P,在CD上的移动速度为Q,在平面上的移动速度R.现在FTD想从A点走 ...

  4. overload(重载) 和 override(重写)的区别

    overload(重载): 重载是基于一个类中,方法名相同,参数列表不同(如果参数列表相同时,参数的类型要不同),与返回值和访问修饰符都无关 如果在面试中就直接说:"同名不同参"  ...

  5. mysql 数据库必会题

    Linux运维班MySQL必会面试题100道 (1)基础笔试命令考察 (要求:每两个同学一组,一个口头考,一个上机实战作答,每5个题为一组,完成后换位) 1.开启MySQL服务 2.检测端口是否运行 ...

  6. IDEA将新建项目上传至GitLab

    1.首先,需要你自己登录GitLab,并新建一个项目的链接,如下图所示: (此图为图三,该链接下面操作中将会用到!) 2.在idea上新建一个项目,完成之后,需要创建一个git仓库: 3.然后可以根据 ...

  7. Bugku 杂项 猜

    猜 说flag是一个人名字的全拼,直接搜图片

  8. ipcloud上传裁切图片,保存为base64再压缩传给后台

    <!doctype html> <html> <head> <meta charset="utf-8"> <meta name ...

  9. [CF938E]Max History题解

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

  10. Activiti7整合SpringBoot(十二)

    1 SpringBoot 整合 Activiti7 的配置 为了能够实现 SpringBoot 与 Activiti7 整合开发,首先我们要引入相关的依赖支持.所以,我们在工程的 pom.xml 文件 ...