CF1097B Petr and a Combination Lock 题解
Content
有一个锁,它只有指针再次指到 \(0\) 刻度处才可以开锁(起始状态如图所示,一圈 \(360\) 度)。
以下给出 \(n\) 个操作及每次转动度数,如果可以通过逆时针或顺时针再次转到 \(0\) 度输出 YES,否则输出 NO。
数据范围:\(1\leqslant n\leqslant 15\),\(1\leqslant a_i\leqslant 180\)。
Solution
不知道为什么 19 年 4 月就做了这题,现在看到这题想写篇题解,于是就有了这篇题解(
我们一看到数据范围 \(n\leqslant 15\),因此可能的选择方向的方案数不会超过 \(2^{15}\)。这是一个非常小的数字,然后你就可以暴搜去一个一个枚举转向方案,看是否有合法的就行了。
Code
#include <cstdio>
#include <algorithm>
using namespace std;
int n, flag, a[20], used[20];
inline void check() {
int sum = 0;
for(int i = 1; i <= n; ++i)
sum += a[i] * (used[i] ? -1 : 1);
if(sum % 360 == 0)
flag = 1;
}
inline void dfs(int x) {
if(x == n + 1)
return check();
dfs(x + 1);
used[x] = 1;
dfs(x + 1);
used[x] = 0;
}
int main() {
scanf("%d", &n);
for(int i = 1; i <= n; ++i)
scanf("%d", &a[i]);
dfs(1);
printf(flag ? "YES" : "NO");
return 0;
}
CF1097B 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- 解决Windows7、Windows10 ping不通的问题
在VLAN交换机网络下面不能访问Windows10或者Windows7共享.ping不通问题,关闭防火墙发现能ping通了共享也正常了. 但是关闭防火墙将给电脑系统留下安全隐患.不怕麻烦的可以继续往下 ...
- layui的动态下拉选
<!--将授权问卷id全部查询出来--> <div class="layui-inline"> <label class="layui-fo ...
- 力扣 - 剑指 Offer 10- I. 斐波那契数列
题目 剑指 Offer 10- I. 斐波那契数列 思路1(递归 / 自顶向下) 这题是很常见的一道入门递归题,可以采用自顶向下的递归方法,比如我们要求第n个位置的值,根据斐波那契数列的定义fib(n ...
- React-native键盘遮挡输入框问题的解决
2016年10月25日更新: 现在有一个更准确一点的做法是用一个View包裹住TextInput,然后通过该View的onLayout方法获取该输入框的y轴位置,再减去一个适当的高度去处理scroll ...
- Codeforces 587D - Duff in Mafia(2-SAT+前后缀优化建图)
Codeforces 题面传送门 & 洛谷题面传送门 2-SAT hot tea. 首先一眼二分答案,我们二分答案 \(mid\),那么问题转化为,是否存在一个所有边权都 \(\le mid\ ...
- FVCOM泥沙模块河流边界处理
简介 入流河流携带泥沙可以按照节点和边界两种形式给定,这两种方法都是在相关的节点上进行直接赋值,并不能保证进入计算域内泥沙总体积. 相关设置 XX_run.nml 河流参数设置 &NML_RI ...
- python-django使用ORM模型增删改查CRUD
from weibo.models import WeiboUser as User user_obj = User.objects.get(pk=1) user_obj.pk Out[4]: 1 u ...
- 01 Windows安装C语言环境
安装C语言运行环境 双击打开安装文件,进行安装 配置环境变量 将: C:\MinGW\bin;添加到Path变量里面. 验证环境变量是否成功 gcc –v 出现如下图所示,证明安装成功
- C语言中的字节对齐
下面这个篇博客讲解很好 http://blog.csdn.net/meegomeego/article/details/9393783 总的来看分三类: 1. 不加 #pragma pack(n)伪指 ...
- A Child's History of England.26
CHAPTER 9 ENGLAND UNDER WILLIAM THE SECOND, CALLED RUFUS William the Red, in breathless haste, secur ...