当前位置:网站首页>多米诺骨牌
多米诺骨牌
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;
}边栏推荐
- [MySQL] Second, the relationship between processes, MySQL password cracking, table building and database building related commands
- 缓存技术使用
- Example of using the cut command
- Excel受保护的工作表怎么操作?
- Simple Factory Pattern
- C# 利用iTextSharp画PDF
- 阿里巴巴官方技术号
- The AD in the library of library file suffix. Intlib. Schlib. Pcblib difference
- 2022.8.8DAY628
- 常用Oracle命令
猜你喜欢

2022-08-08: Given an array arr, it represents the height of the missiles that will appear in order from morning to night.When the cannon shoots missiles, once the cannon is set to shoot at a certain h

CMake中INSTALL_RPATH与BUILD_RPATH问题

字节跳动面试题之镜像二叉树2020

The solution that does not work and does not take effect after VScode installs ESlint

db.sqlite3没有“as Data Source“解决方法

IQ Products CMV Brite Turbo试剂盒的原理

Error jinja2.exceptions.UndefinedError: 'form' is undefined

jvm线程状态

普罗米修斯原理及节点发布

Leetcode 70 stairs issues (Fibonacci number)
随机推荐
Import the pycharm environment package into another environment
How to find package information and pin definitions for NXP S32K1xx series microcontrollers
语句加锁分析
工控设备的系统如何进行加固
io.lettuce.core.RedisCommandTimeoutException Command timed out
逆向工程
Gao Zelong, a famous digital collection expert and founder of the Digital Collection Conference, was interviewed by China Entrepreneur Magazine
[GO], arrays and slices
IQ Products巨细胞病毒CMV感染检测试剂盒的特征和应用
db.sqlite3没有“as Data Source“解决方法
.NET高级技术
Excel受保护的工作表怎么操作?
shardingsphere数据分片配置项说明和示例
golang xml 处理动态属性
Fragments
电学知识的疑问
A test engineer with an annual salary of 35W was laid off. Personal experience: advice that you have to listen to
bzoj 5333 [Sdoi2018]荣誉称号
常用Oracle命令
中英文说明书丨CalBioreagents 山羊抗人白蛋白,IgG组分