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. MongoDB的特殊操作

    相比关系型数据库, Array [1,2,3,4,5] 和 Object { 'name':'DragonFire' } 是MongoDB 比较特殊的类型了 特殊在哪里呢?在他们的操作上又有什么需要注 ...

  2. 运行biggan demo

    http://www.zhuanzhi.ai/document/8705953a704e1bf8e051c161d1587d88

  3. 【PowerOJ1744&网络流24题】方格取数问题(最小割)

    题意: n,m<=30 思路: [问题分析] 二分图点权最大独立集,转化为最小割模型,从而用最大流解决. [建模方法] 首先把棋盘黑白染色,使相邻格子颜色不同,所有黑色格子看做二分图X集合中顶点 ...

  4. 洛谷P4391 [BOI2009]Radio Transmission 无线传输——题解

    题目传送 假如我们有一个用于循环连接的最短串ans,考虑用它造出来的数据(即输入的字符串s)有什么特点.发现:ans自我连接出一个大串z后从中取出的一个子串即为s,对s造一个KMP算法中的next数组 ...

  5. Are We Ready for SDN? Implementation Challenges for Software-Defined Networks

    Name of article:Are We Ready for SDN?  Implementation Challenges for  Software-Defined Networks Orig ...

  6. Spring Cloud架构教程 (五)服务网关(过滤器)

    过滤器的作用 通过上面所述的两篇我们,我们已经能够实现请求的路由功能,所以我们的微服务应用提供的接口就可以通过统一的API网关入口被客户端访问到了.但是,每个客户端用户请求微服务应用提供的接口时,它们 ...

  7. Kaggle 入门资料

    kaggle入门之如何使用 - CSDN博客 http://blog.csdn.net/mdjxy63/article/details/78221955 kaggle比赛之路(一) -- 新手注册账号 ...

  8. 查看jQuery file upload的image preview如何工作的

    查看readme中的说明, JavaScript Load Image library v. 1.13.0+: Required for the image previews and resizing ...

  9. 高通Camera驱动分析【转】

    本文转载自:http://blog.csdn.net/liwei16611/article/details/53955711 1.Sensor slave配置 结构体msm_camera_sensor ...

  10. mvn 与 pom.xml

    mvn 安装 wget http://mirrors.hust.edu.cn/apache//maven/maven-3/3.0.5/binaries/apache-maven-3.0.5-bin.t ...