A - pSort

One day n cells of some array decided to play the following game. Initially each cell contains a number which is equal to it's ordinal number (starting from 1). Also each cell determined it's favourite number. On it's move i-th cell can exchange it's value with the value of some other j-th cell, if |i - j| = di, where di is a favourite number of i-th cell. Cells make moves in any order, the number of moves is unlimited.

The favourite number of each cell will be given to you. You will also be given a permutation of numbers from 1 to n. You are to determine whether the game could move to this state.

Input

The first line contains positive integer n (1 ≤ n ≤ 100) — the number of cells in the array. The second line contains n distinct integers from 1 to n — permutation. The last line contains n integers from 1 to n — favourite numbers of the cells.

Output

If the given state is reachable in the described game, output YES, otherwise NO.

Sample 1

InputcopyOutputcopy
5
5 4 3 2 1
1 1 1 1 1
YES

Sample 2

InputcopyOutputcopy
7
4 3 5 1 2 7 6
4 6 6 1 6 6 1
NO

Sample 3

InputcopyOutputcopy
7
4 2 5 1 3 7 6
4 6 6 1 6 6 1
YES
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxx=1e2+100;
int f[maxx];
int a[maxx];
int n;
inline int getf(int u)
{
	if(u==f[u]) 
	return u;
	else 
	return f[u]=getf(f[u]);
}
inline void merge(int u,int v)
{
	int t1=getf(u);
	int t2=getf(v);
	if(t1!=t2)
	{
		f[t1]=t2;
	}
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) 
	scanf("%d",&a[i]),f[i]=i;
	int x;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&x);
		if(i-x>=1) 
		merge(i,i-x);
		if(i+x<=n) 
		merge(i,i+x);
	}
	int flag=0;
	for(int i=1;i<=n;i++)
	{
		if(getf(a[i])!=getf(i)) 
		{
			flag=1;
			break;
		}
	}
	if(flag) 
	puts("NO");
	else 
	puts("YES");
}

 

import time import openpyxl from selenium import webdriver from bs4 import BeautifulSoup # 设置请求头,模拟真实浏览器访问 headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36', } # 使用Selenium启动浏览器 driver = webdriver.Chrome() data = [] counter = 1 # 序列号计数器 # 打开网页 for i in range(1,6): url = 'https://search.jd.com/Search?keyword=%E6%89%8B%E6%9C%BA&psort=3&wq=%E6%89%8B%E6%9C%BA&psort=3&pvid=0faa3ec65d444d68a66161cdf464d451&psort=3&page={}&s=61&click=0'.format( (i * 2) - 1) driver.get(url) # 模拟滚动页面,以触发异步请求加载更多商品信息 driver.execute_script('window.scrollTo(0, document.body.scrollHeight);') time.sleep(2) # 获取完整页面内容 html = driver.page_source # 解析网页内容,提取商品名称和价格信息 soup = BeautifulSoup(html, 'html.parser') products = soup.select('.gl-item') for product in products: product_id = product['data-sku'] # 提取产品ID name = product.select('.p-name em')[0].text.strip() product_url = 'https:' + product.select('.p-name a')[0]['href'] # 修改产品URL price = product.select('.p-price strong i')[0].text.strip() data.append([counter, product_id, name, product_url, price]) # 将产品数据添加到列表中 counter += 1 # 每个产品的增量计数器 # 关闭浏览器 driver.quit() # 创建Excel文件并保存数据 wb = openpyxl.Workbook() ws = wb.active ws.append(['top', '商品ID', '商品名称', '商品链接', '价格']) # 添加已修改列顺序的标题行 for item in data: ws.append(item) wb.save('jd_top300.xlsx') print("数据已保存到jd_top300.xlsx文件。")
06-02
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值