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. Java_环境变量

    介绍 第一步:下载JDK 第二步:搭建环境,双击JDK安装程序 第三步:配置环境变量 第四步:检查JDK安装是否成功 介绍: .java 源文件 我们所编写的代码都在这个文件中 .class 字节码文 ...

  2. git的fetch

    1.git fetch 会从远程分支上下载 2.git pull 会将本地库更新至远程库最新状态

  3. 15 Spring Boot Shiro 验证码

    1. <dependency> <groupId>com.github.axet</groupId> <artifactId>kaptcha</a ...

  4. 软件安装——JRE多版本问题

    [Q]运行UMongo.exe文件时显示错误信息“The registry refers to a nonexsistent JAVA Runtime Envioroment or the Runti ...

  5. 【bzoj3463】[COCI2012] Inspector

    *题目描述: 在一个小国家中,一个新的小镇终于建成了!如往常一样,Mirko获得了“首席税务巡查员”的职位.他的任务是保证正确地计算各公司的收入情况.一共有N家办公室坐落在主干道上,从左到右被编号为1 ...

  6. Content-type的几种常见类型

    一.是什么? 是Http的实体首部字段,用于说明请求或返回的消息主体是用何种方式编码,在request header和response header里都存在. 二.几个常用类型: 1.applicat ...

  7. 使用JLDAP操作LDAP,包含匿名连接、ldif导入导出、获取根节点、对数据的操作、LDAP错误码解析等

    bean类 package com.cn.ccc.ggg.ldap.model; import javax.persistence.Entity; import javax.persistence.T ...

  8. Java网络编程与NIO详解11:Tomcat中的Connector源码分析(NIO)

    本文转载 https://www.javadoop.com 本系列文章将整理到我在GitHub上的<Java面试指南>仓库,更多精彩内容请到我的仓库里查看 https://github.c ...

  9. ELK实时日志分析平台环境部署--完整记录(ElasticSearch+Logstash+Kibana )

    https://blog.csdn.net/oLevin/article/details/81020794

  10. ORACLE Physical Standby DG 之switch over

    DG架构图如下: 计划,切换之后的架构图: DG切换: 主备切换:这里所有的数据库数据文件.日志文件的路径是一致的 [旧主库]主库primarydb切换为备库standby3主库检查switchove ...