当前位置:网站首页>多米诺骨牌
多米诺骨牌
2022-08-09 06:34:00 【未央吖】
A-多米诺骨牌_长沙学院2022暑假训练赛(一) (nowcoder.com)
题目描述
多米诺骨牌(domino)是一种木制、骨制或塑料制成的长方体骨牌,按一定间距排列成行,轻轻碰倒第一枚骨牌,其余的骨牌就会产生连锁反应,依次倒下。
我们将这个多米诺骨牌的连锁反应简化,假设一个骨牌受到大于 ggg 的力就会倒塌。当它因收到来自左侧的力倒塌时,它就会向右侧倒去,同时对右侧的骨牌施加大小为 aaa 的力。另一侧的方向相反,aaa 大小不变。
Bruce12138有 nnn 个多米诺骨牌排成一列,第 iii 个骨牌受到大于 gig_igi 的力后才会倒塌,倒塌后将对倒塌方向的下一个骨牌施加 aia_iai 的力。Bruce12138想要找到一个位置,这个位置在两个骨牌的中间,或者在最左侧骨牌的左边,或者在最右侧骨牌的右边。然后他会在一次推倒操作中,推倒这个位置左右两侧的骨牌(可以没有)。请问他能否通过一次推倒操作使得所有的多米诺骨牌都倒下?
能则输出"Yes",不能则输出"No",不含引号。
输入描述:
第一行一个整数 n(1≤n≤105)n(1\le n\le10^5)n(1≤n≤105) ,表示多米诺骨牌的数量。 第二行 nnn 个用空格分开的整数,表示第 iii 个骨牌能对下一个骨牌施加的力 ai(1≤ai≤105)a_i(1\le a_i\le 10^5)ai(1≤ai≤105)。 第三行 nnn 个用空格分开的整数,表示第 iii 个骨牌受到大于 gi(1≤gi≤105)g_i(1\le g_i\le 10^5)gi(1≤gi≤105) 的力就会倒塌。
输出描述:
一行一个字符串,表示能否通过一次推倒操作使得所有的多米诺骨牌都倒下。
示例1
输入
复制2 2 2 1 1
2 2 2 1 1
输出
复制Yes
Yes
说明
在任何一个位置都可以推倒全部的多米诺骨牌。
代码:
#include<bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[100005] = {}, b[100005] = {};
for (int i = 0; i < n; i++) {cin >> a[i];}
for (int i = 0; i < n; i++) {cin >> b[i];}
for (int i = 0; i < n; i++) {if (a[i] < b[i + 1] || a[i] < b[i - 1]){ cout << "No";return 0;}}
cout << "Yes";
return 0;
}
方法二比较好理解
#include<bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[100005] = {}, b[100005] = {};
for (int i = 0; i < n; i++) {cin >> a[i];}
for (int i = 0; i < n; i++) {cin >> b[i];}
int i = 0, j = n;
for (; i < n - 1; i++) {
if (a[i] <= b[i + 1])break;
}
for (; j >= 1; j--) {
if (a[j] <= b[j - 1])break;
}
int flag = 0;
if (i >= j - 1) flag = 1;
if (flag) cout << "Yes";
else cout << "No";
return 0;
}
边栏推荐
- 移远EC20 4G模块拨号相关
- Unity C# 委托——事件,Action,Func的作用和区别
- 运放-运算放大器经典应用电路大全-应用电路大全
- Output method of list string print(*a) print(““.join(str(c) for c in a) )
- C语言的内置宏(定义日志宏)
- pdf加密、找回密码
- Teach you how to make the Tanabata meteor shower in C language - elegant and timeless (detailed tutorial)
- After the VB.net program is closed, the background is still connected to SQL
- 代码目录结构
- workbench 数据导出
猜你喜欢
db.sqlite3 has no "as Data Source" workaround
pycharm环境包导入到另外一个环境
mongo+ycsb性能测试及线程数分析
推进产教融合 赋能教育创新发展 | 华云数据荣获“企业贡献奖”
Use of PlantUML plugin in idea
INSTALL_RPATH and BUILD_RPATH problem in CMake
Gao Zelong, a famous digital collection expert and founder of the Digital Collection Conference, was interviewed by China Entrepreneur Magazine
leetcode 之 零移位
ByteDance Interview Questions: Mirror Binary Tree 2020
flask创建数据库失败未报错
随机推荐
中英文说明书丨TRC 交替醇(Catalogue NumberA575760)
longest substring without repeating characters
抗菌药物丨Toronto Research Chemicals 天冬酰胺D
Xilinx Zynq ZynqMP DNA
单例模式
sql problem solving statement to create a table
PDF不能打印和复制的问题如何解决?
报错:FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disab
简单使用Lambda表达式
C语言的内置宏(定义日志宏)
逆向工程
P7阿里面试题2020.07 之滑动窗算法(阿里云面试)
Thread Pool Summary
C# 利用iTextSharp画PDF
[MySQL] Second, the relationship between processes, MySQL password cracking, table building and database building related commands
Silently start over, the first page is also a new page
推进产教融合 赋能教育创新发展 | 华云数据荣获“企业贡献奖”
线程的6种状态
shardingsphere data sharding configuration item description and example
Use of PlantUML plugin in idea