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 ...
随机推荐
- App 端自动化的最佳方案,完全解放双手!
1. 前言 大家好,我是安果! 之前写过一篇文章,文中提出了一种方案,可以实现每天自动给微信群群发新闻早报 如何利用 Python 爬虫实现给微信群发新闻早报?(详细) 但是对于很多人来说,首先编写一 ...
- Electron快速入门之debug
view->toggleDevelpper Tools 本地桌面调试 浏览器debug "start": "electron --inspect=5858 .&qu ...
- 直接插入100w数据报错
### Cause: com.mysql.cj.jdbc.exceptions.PacketTooBigException: Packet for query is too large (77,600 ...
- 从零开始学Kotlin第二课
字符串模板 fun main(args:Array<String>){ //主函数main方法 println(diaryGenerater("天安门")); } // ...
- Java 中的监控与管理原理概述
点赞再看,动力无限.Hello world : ) 微信搜「程序猿阿朗 」. 本文 Github.com/niumoo/JavaNotes 和 程序猿阿朗博客 已经收录,有很多知识点和系列文章. 当前 ...
- web渗透工程师学习
职位描述: 对公司网站.业务系统进行安全评估测试(黑盒.白盒测试): 对公司各类系统进行安全加固: 对公司安全事件进行响应,清理后门,根据日志分析攻击途径: 安全技术研究,包括安全防范技术,黑客技术等 ...
- Kubernetes-网络
前言 本篇是Kubernetes第十一篇,大家一定要把环境搭建起来,看是解决不了问题的,必须实战,此篇文章概念比较多,后续我会继续出一些网络相关实战以及原理探索篇. Kubernetes系列文章: K ...
- 洛谷 P6222 - 「P6156 简单题」加强版(莫比乌斯反演)
原版传送门 & 加强版传送门 题意: \(T\) 组数据,求 \(\sum\limits_{i=1}^n\sum\limits_{j=1}^n(i+j)^k\mu^2(\gcd(i,j))\g ...
- Atcoder Grand Contest 001E - BBQ Hard(组合意义转化,思维题)
Atcoder 题面传送门 & 洛谷题面传送门 Yet another 思维题-- 注意到此题 \(n\) 数据范围很大,但是 \(a_i,b_i\) 数据范围很小,这能给我们什么启发呢? 观 ...
- R合并数据框有重复匹配时只保留第一行
前言 合并数据框有重复匹配时通常会返回所有的匹配,如何只保留匹配的第一行呢?其实这个需求也很常见.如芯片探针ID和基因ID往往多对一,要合并ID对应矩阵和芯片表达矩阵时. 数据例子 data = da ...