当前位置:网站首页>AcWing 4498. 指针 (DFS)
AcWing 4498. 指针 (DFS)
2022-07-24 02:46:00 【GHOSTANDBREAD】
题目链接:4498. 指针 - AcWing题库
给定一个如下图所示的全圆量角器。

初始时,量角器上的指针指向刻度 00。
现在,请你对指针进行 nn 次拨动操作,每次操作给定一个拨动角度 aiai,由你将指针拨动 aiai 度,每次的拨动方向(顺时针或逆时针)由你自由决定。
请你判断,能否通过合理选择每次拨动的方向,使得指针最终仍然指向刻度 00。
输入格式
第一行包含整数 nn。
接下来 nn 行,每行包含一个整数 aiai,表示一次操作的拨动角度。
输出格式
如果可以做到指针最终仍然指向刻度 00,则输出 YES,否则输出 NO。
数据范围
前 44 个测试点满足 1≤n≤31≤n≤3。
所有测试点满足 1≤n≤151≤n≤15,1≤ai≤1801≤ai≤180。
输入样例1:
3
10
20
30
输出样例1:
YES
输入样例2:
3
10
10
10
输出样例2:
NO
输入样例3:
3
120
120
120
输出样例3:
YES代码:
#include<bits/stdc++.h> // 每次都有两种选择,则可以dfs暴搜
using namespace std;
#define endl "\n"
int n, a[20];
bool flag;
void dfs(int u, int s) {
if(s == n) {
if(u == 0) {
if(!flag) { // 没输出过就输出
cout << "YES" << endl;
flag = true; // 输出过就标记一下,只能输出一次
return;
}
}
return;
}
dfs((u + a[s] + 360) % 360, s + 1); // 加上
dfs((u - a[s] + 360) % 360, s + 1); // 减去
}
int main() {
ios::sync_with_stdio(false);
cout.tie(0);
cin >> n;
for(int i = 0; i < n; i ++) cin >> a[i];
dfs(0, 0);
if(!flag) cout << "NO" << endl; // 没被标记过,则没输出过,即不可以
return 0;
}边栏推荐
- 【英雄哥七月集训】第 23天: 字典树
- 【补题日记】[2022杭电暑期多校1]C-Backpack
- Description of relevant resolutions in video on demand
- 【补题日记】[2022杭电暑期多校1]B-Dragon slayer
- SSM's technical forum includes front and back offices
- Detailed vector
- TP5 framework link promotion project
- Analyze the space practice field required by maker education activities
- 508. 出现次数最多的子树元素和-哈希表法纯c实现
- About offline use of SAP Fiori application
猜你喜欢

让生活充满幸福感

攻防世界WEB练习区(backup、cookie、disabled_button)

22 -- range and of binary search tree

SSM family financial management personal financial management system accounting system
![[datasets] - downloading some datasets of flyingthings3d optical flow](/img/00/5d87b378ebab49e9dc400d8e3634f3.png)
[datasets] - downloading some datasets of flyingthings3d optical flow

To forge ahead on a new journey, the city chain science and technology carnival was grandly held in Xiamen

Wonderful! The description of meituan Octo distributed service management system is too clear

7 issues to consider before website construction

Unity timeline tutorial

Liveqing live broadcast on demand streaming media OBS streaming live broadcast how to obtain interface verification token video verification streamtoken and configure token validity
随机推荐
[knowledge atlas] practice -- Practice of question and answer system based on medical knowledge atlas (Part2): Atlas data preparation and import
[untitled]
Soft test --- fundamentals of programming language (Part 1)
Mysql数据库,分组函数篇
(6) Decorator extension [email protected] Principle of use
508. The subtree element with the most occurrences and the pure C implementation of hash table method
理解加载class到JVM的时机
rust allow dead_ code
js傳參時傳入 string有數據;傳入 number時沒有數據;2[0]是對的!number類型數據可以取下標
compostion-api(setup中) watch使用细节
ssm的求职招聘系统兼职应聘求职
[FPGA tutorial case 38] communication case 8 - serial parallel serial data transmission based on FPGA
SSM家庭理财个人理财管理系统记账系统
Why use the well architected framework?
通用机环境下安全版单机数据库使用非root用户管理的解决方案
summernote富文本编辑器
The practical influence of educational robot on students' learning effect
Only beautiful ones can be opened
22 -- 二叉搜索树的范围和
Liveqing live RTMP on demand video streaming platform how to carry the Sid and token returned by the login interface to call authentication streamtoken video streaming authentication