当前位置:网站首页>多米诺骨牌
多米诺骨牌
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;
}
边栏推荐
- 网络学习总结
- vim 程序编辑器的基本操作(积累)
- P7 Alibaba Interview Questions 2020.07 Sliding Window Algorithm (Alibaba Cloud Interview)
- Program Performance Analysis - Complexity Analysis
- Fragments
- io.lettuce.core.RedisCommandTimeoutException Command timed out
- e-learning summary
- crc calculation
- PDF不能打印和复制的问题如何解决?
- 运算放大器(OPA)超详细参数讲解-运放---以及8个型号的运算放大器分析对比
猜你喜欢
static静态关键字和继承
C语言实现顺序栈和链队列
字节跳动笔试题2020 (抖音电商)
pycharm环境包导入到另外一个环境
变压器的工作原理(图解,原理图讲解,一看就懂)
ByteDance Written Exam 2020 (Douyin E-commerce)
idea中PlantUML插件使用
Use of PlantUML plugin in idea
C# 利用iTextSharp画PDF
Teach you how to make the Tanabata meteor shower in C language - elegant and timeless (detailed tutorial)
随机推荐
Program Performance Analysis - Complexity Analysis
Import the pycharm environment package into another environment
【Wwise】ArgumentException: The specified path is not of a legal form (empty). About the path reading error in WwiseGlobal
Explain the wait() function and waitpid() function in C language in detail
Excel受保护的工作表怎么操作?
Singleton DCL (double check the lock) full han mode and the hungry
治疗消化性溃疡—Toronto Research Chemicals 甘氨酸铝
XxlJobConfig分布式定时器任务管理XxlJob配置类,替代
Thread Pool Summary
2022.8.8DAY628
BeautifulSoup4的介绍与使用
The AD in the library of library file suffix. Intlib. Schlib. Pcblib difference
按图搜索1688商品接口(item_search_img-按图搜索1688商品(拍立淘接口)代码对接教程
Data center project preliminary summary
golang xml 处理动态属性
Unity backgammon game design and simple AI implementation (1)
Remember a nest.js route that matches all the path problems that follow
How to find package information and pin definitions for NXP S32K1xx series microcontrollers
flask创建数据库失败未报错
Teach you how to make the Tanabata meteor shower in C language - elegant and timeless (detailed tutorial)