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 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.
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.
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).
3
10
20
30
YES
3
10
10
10
NO
3
120
120
120
YES
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.
前 i 次旋转下,是否可以旋转到 j 度的位置,那么转移方程有:dp[i][j] = dp[ i - 1 ][ j - a[i] ] | dp[ i - 1 ][ j + a[i] ]
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <numeric>
#include <cmath>
#include<unordered_set>
#define ll long long
using namespace std;
int dir[][] = { {,},{-,},{,},{,-} }; int main()
{
int n;
cin >> n;
vector<int> a(n+1);
for (int i = 1; i <= n; i++)
cin >> a[i];
vector<vector<bool>> dp(16, vector<bool>(360));
dp[0][0] = true;
for (int i = 1; i <= n; i++)
{
for (int j = 0; j < 360; j++)
{
if (dp[i - 1][(j - a[i] + 360) % 360])
dp[i][j] = true;
if (dp[i - 1][(j + a[i] + 360) % 360])
dp[i][j] = true;
}
}
cout << (dp[n][0] ? "YES" : "NO") << endl;
//system("pause");
return 0;
}
Petr and a Combination Lock的更多相关文章
- B.Petr and a Combination Lock
https://codeforces.com/contest/1097/problem/A Petr and a Combination Lock time limit per test 1 seco ...
- CF1097B Petr and a Combination Lock 题解
Content 有一个锁,它只有指针再次指到 \(0\) 刻度处才可以开锁(起始状态如图所示,一圈 \(360\) 度). 以下给出 \(n\) 个操作及每次转动度数,如果可以通过逆时针或顺时针再次转 ...
- Combination Lock
时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Finally, you come to the interview room. You know that a Micr ...
- hihocoder #1058 Combination Lock
传送门 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Finally, you come to the interview room. You know that a ...
- 贪心 Codeforces Round #301 (Div. 2) A. Combination Lock
题目传送门 /* 贪心水题:累加到目标数字的距离,两头找取最小值 */ #include <cstdio> #include <iostream> #include <a ...
- 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 ...
- Hiho----微软笔试题《Combination Lock》
Combination Lock 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Finally, you come to the interview room. You ...
- CF #301 A :Combination Lock(简单循环)
A :Combination Lock 题意就是有一个密码箱,密码是n位数,现在有一个当前箱子上显示密码A和正确密码B,求有A到B一共至少需要滚动几次: 简单循环:
- hihocoder-第六十一周 Combination Lock
题目1 : Combination Lock 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Finally, you come to the interview roo ...
随机推荐
- Django文件夹
Django文件 App文件夹 migrations文件 生成models创建表的翻译语句 telemplatetags文件夹 telemplatetags文件夹下的文件专门用来创建自定义标签.自定义 ...
- actiBPM插件的办法
1.下载actiBPM到本地 从IDEA官网下载actiBPM.jar包 IDEA官网:https://plugins.jetbrains.com/ 官网搜索actiBPM 2.从本地安装actiBP ...
- Grafana展示zabbix监控数据
一.安装步骤 (1)进入官网选择合适的操作系统版本下载Grafana:https://grafana.com/grafana/download?platform=linux [root@zabbix- ...
- MS yc
# word - operate标题栏 菜单栏 工具栏 页面 状态栏 字体阴影 背景色 着重号 项目符号 数字编码 格式刷
- python3练习100题——025
原题链接:http://www.runoob.com/python/python-exercise-example25.html 题目:求1+2!+3!+...+20!的和. 我的代码: s =[] ...
- vue插槽的使用
一.插槽的基本使用 二.具名插槽的使用 三.编译作用域的例子 四.作用域插槽 一.插槽的基本使用 1.插槽的基本使用<slot></slot> 2.插槽的默认值 ...
- DisplayNameFor()方法的工作原理
DisplayNameFor()方法的工作原理原创Peter Yelnav 最后发布于2018-11-23 11:09:51 阅读数 1308 收藏展开最近研究了一下ASP.NET MVC,困惑于视图 ...
- 需要再次删除清空部署才能用rancher部署成功的是docker有问题
需要再次删除清空部署才能用rancher部署成功的是docker有问题 待办 可以解释为什么一定要用特定的docker版本
- crontab调用python脚本新思路
crontab调用python脚本文件,有可能失败,定时执行并没有执行,怎么办? 答:写一个shell脚本调用python,然后用crontab调用shell脚本.具体细节,有时间补充. ————— ...
- wamp选择语言
桌面右下角 右击绿色小图标 点击language选择chinese