40pts,求助求助!
查看原帖
40pts,求助求助!
600315
neilliu楼主2023/10/6 22:12
#include <bits/stdc++.h>
using namespace std;
void solve(){
	int n,t[2005],b[2005],a[2005];
	scanf("%d",&n);
	for(int i = 1; i <= n; i++) scanf("%d",&t[i]);
	for(int i = 1; i <= n; i++) scanf("%d",&b[i]);
	for(int i = 1; i <= n; i++) a[i] = 0;
	for(int i = 1; i <= n; i++) if(t[i] > b[i]){printf("No\n"); return ;}
	for(int i = 0; i <= 2000; i++){
		for(int j = 1; j <= n; j++) a[j] = i * t[j];
		reverse(t+1,t+n+1);
		bool ok = 1;
		int cnt = -1,cnt2;
 		for(int j = 1; j <= n; j++){
			if(a[j] > b[j]) ok = 0;
			if((b[j] - a[j]) % t[j] != 0) ok = 0;
			cnt2 = cnt,cnt = (b[j] - a[j]) / t[j];
			if(j != 1 && cnt != cnt2) ok = 0;
		}
		if(ok){
			printf("Yes\n"); return ;
		}
		reverse(t+1,t+n+1);
	}
	printf("No\n"); return ;
}
int main()
{
	int T; scanf("%d",&T);
	while(T--) solve();
	return 0;
}

对了5-12,23,24

2023/10/6 22:12
加载中...