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 ...
随机推荐
- 五、Zookeeper的Shell操作
前文 一.CentOS7 hadoop3.3.1安装(单机分布式.伪分布式.分布式 二.JAVA API实现HDFS 三.MapReduce编程实例 四.Zookeeper3.7安装 Zookeepe ...
- 前端:WebP自适应实践
WebP介绍 WebP 是 Google 推出的一种同时提供了有损和无损两种压缩方式的图片格式,优势体现在其优秀的图像压缩算法,能够带来更小的图片体积,同时拥有更高的的图像质量.根据官方说明,WebP ...
- Docker之容器化学习之路v20.10.3
Docker概述 **本人博客网站 **IT小神 www.itxiaoshen.com Docker文档官网 Docker是一个用于开发.发布和运行应用程序的开放平台.Docker使您能够将应用程序与 ...
- Atcoder Regular Contest 096 D - Sweet Alchemy(贪心+多重背包)
洛谷题面传送门 & Atcoder 题面传送门 由于再过 1h 就是 NOI 笔试了所以题解写得会略有点简略. 考虑差分,记 \(b_i=c_i-c_{fa_i}\),那么根据题意有 \(b_ ...
- R数据科学-3
R数据科学(R for Data Science) Part 3:编程 转换--可视化--模型 --------------第13章 使用magrittr进行管道操作----------------- ...
- 学习java 7.13
学习内容: 一个汉字存储:如果是GBK编码,占用2个字节:如果是UTF-8编码,占用3个字节 汉字在存储的时候,无论选择哪种编码存储,第一个字节都是负数 字符流=字节流+编码表 采用何种规则编码,就要 ...
- accustom
近/反义词: acclimatize, familiarize, habituate, inure, get used to, orient; alienate, estrange, wean New ...
- Scala(七)【异常处理】
目录 一.try-catch-finally 二.Try(表达式).getOrElse(异常出现返回的默认值) 三. 直接抛出异常 一.try-catch-finally 使用场景:在获取外部链接的时 ...
- Express中间件原理详解
前言 Express和Koa是目前最主流的基于node的web开发框架,他们的开发者是同一班人马.貌似现在Koa更加流行,但是仍然有大量的项目在使用Express,所以我想通过这篇文章说说Expres ...
- 3.5 Rust Generic Types, Traits, and Lifetimes
Every programming language has tools for effectively handling the duplication of concepts. In Rust, ...