C. Madoka and Formal Statement Codeforces Round #818 (Div. 2)

这篇博客讨论了一个数组处理问题,给定两个数组a和b,判断是否能通过一系列特定操作(数组元素加1,最后一个元素可加2)使a转换成b。文章中提供了C++代码实现,通过比较数组元素和检查相邻元素差值来确定能否完成转换,并输出结果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

 

题意;给你一个a数组和b数组,问你能不能通过任意次操作使a得到b

对于这个操作的介绍是如果a_i>=a_i+1,那么a_i可以选择+1,特殊的在i为n时,如果a_1>=a_n

a_n可以选择+1.

思路;因为a数组要经过变换得到b数组,而如果b_i-b_i+_1>1,那么如果a_i!=b_i,那么a_i就不能通过a_i+_1a_i变成b_i(因为a_i+_1最大也只能是b_i+_1),然后直接flag=true,

最后直接判断输出即可。

代码

/**
*  ┏┓   ┏┓+ +
* ┏┛┻━━━┛┻┓ + +
* ┃       ┃
* ┃   ━   ┃ ++ + + +
*  ████━████+
*  ◥██◤ ◥██◤ +
* ┃   ┻   ┃
* ┃       ┃ + +
* ┗━┓   ┏━┛
*   ┃   ┃ + + + +Code is far away from  
*   ┃   ┃ + bug with the animal protecting
*   ┃    ┗━━━┓ 神兽保佑,代码无bug 
*   ┃  	    ┣┓
*    ┃        ┏┛
*     ┗┓┓┏━┳┓┏┛ + + + +
*    ┃┫┫ ┃┫┫
*    ┗┻┛ ┗┻┛+ + + +
*/

#include<cstdio>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include<vector>
#include<queue>
#include<map>
#define sc_int(x) scanf("%d", &x)
#define sc_ll(x) scanf("%lld", &x)
#define pr_ll(x) printf("%lld", x)
#define pr_ll_n(x) printf("%lld\n", x)
#define pr_int_n(x) printf("%d\n", x)
#define ll long long 
using namespace std;

const int N=1000000+100;
int n ,m,h;
int a[N],b[N];



int main()
{
	int t;
	sc_int(t);
	while(t--)
	{
		sc_int(n);
		bool flag=0;
		for(int i =1;i<=n;i++)
		sc_int(a[i]);
		for(int i=1;i<=n;i++){
		sc_int(b[i]);			
		if(a[i]>b[i])flag=1;

		}
		for(int i =1;i<n;i++)
		{
			if(b[i]-b[i+1]>1)
			{
				if(b[i]!=a[i])
				flag=1;
			}
		}
		if(b[n]-b[1]>1)
		{
			if(b[n]!=a[n])
			flag=1;
		}
		if(flag)cout<<"NO\n";
		else cout<<"YES\n";

	}
	
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值