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 题解的更多相关文章

  1. B.Petr and a Combination Lock

    https://codeforces.com/contest/1097/problem/A Petr and a Combination Lock time limit per test 1 seco ...

  2. 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 ...

  3. 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 ...

  4. Combination Lock

    时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Finally, you come to the interview room. You know that a Micr ...

  5. hihocoder #1058 Combination Lock

    传送门 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Finally, you come to the interview room. You know that a ...

  6. 贪心 Codeforces Round #301 (Div. 2) A. Combination Lock

    题目传送门 /* 贪心水题:累加到目标数字的距离,两头找取最小值 */ #include <cstdio> #include <iostream> #include <a ...

  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. 数字逻辑实践3->EDA技术与Verilog设计

    本文属于EDA技术概述类文章 1 EDA技术及其发展 概念 EDA(Electronic Design Automation),指的是以计算机为工作平台,以EDA软件工具为开发环境,以PLD期间或者A ...

  2. Ubuntu压缩和解压缩

    1.常用的压缩格式 tar tar.bz2 tar.gz 2.gzip压缩 gzip xxx //压缩 gzip -d xxx.gz //解压缩 gzip对文件夹的压缩 gzip -r xxx //文 ...

  3. spring boot的mybatis开启日志

    logging: level: com: xxx: xxxx: xxxx: mapper: DEBUG logging.level.mapper对应的包名=DEBUG

  4. 使用apt安装docker

    使用apt安装docker # 更新数据源 apt-get update # 安装所需依赖 apt-get -y install apt-transport-https ca-certificates ...

  5. [SQL]SQL Server 锁表

    -- 查看被锁表: SELECT request_session_id spid, -- 锁表进程 OBJECT_NAME(resource_associated_entity_id) tableNa ...

  6. 『学了就忘』Linux权限管理 — 56、不可改变位权限(chattr)

    目录 1.命令格式 2.查看文件系统属性chattr权限 3.示例 文件系统属性chattr权限,也叫不可改变位权限,该权限没有风险,但是他能限制root用户. 1.命令格式 [root@localh ...

  7. 矩阵树定理&BEST定理学习笔记

    终于学到这个了,本来准备省选前学来着的? 前置知识:矩阵行列式 矩阵树定理 矩阵树定理说的大概就是这样一件事:对于一张无向图 \(G\),我们记 \(D\) 为其度数矩阵,满足 \(D_{i,i}=\ ...

  8. 洛谷 P5224 - Candies(循环卷积)

    洛谷题面传送门 一道题解长度大概不到 1k 的题,可还是决定写篇题解,因为自己没有做出来( \(1004535809\) 好评( 首先这个 \(\equiv m\pmod{k}\) 有点把我们往单位根 ...

  9. R语言与医学统计图形-【11】ggplot2几何对象之散点图

    ggplot2绘图系统--几何对象之散点图 以geom开头的函数超过30个.几何对象和标度函数scale密不可分.只有在aes中传入某个变量,scale才能发挥作用. 所谓标度scale,就是图形遥控 ...

  10. MYSQL5.8-----5