玲珑Round #7-1071 - Boring Game

1071 - Boring Game

Time Limit:1s Memory Limit:1024MByte

Submissions:612Solved:200

DESCRIPTION

In a mysterious cave, PigVan ( Mr.Van's pet ) has lived for thousands years. PigVan absorbed the power of nature, and it may pretend a human in speaking, walking and so on.

One day, he bought some valuable stone, and divided them into n piles of stone where the ith pile (1≤i≤n) contains values ai .

After PigVan put them in a line, he wants to play a game.

In the boring game, he can do this operation:

Choose a stone pile ai (i>1)and its two adjacent piles ai-1, ai+1, turn (ai-1, ai, ai+1) to (ai-1 + ai, -ai, ai + ai+1).

PigVan wonders whether he can get (b1, b2, b3, …, bn) after several operations.

Note:

If you choose the last pile an, the operation will be ( an-1 + an, -an ) .

INPUT
The first line is a single integer TT, indicating the number of test cases.
For each test case:
In the first line, there are only one integer nn(n≤10 5), indicating the number of food piles.
The second line is nn integers indicate sequence aa ( | a i | ≤ 10 6).
The third line is nn integers indicate sequence bb ( | b i | ≤ 10 6).
OUTPUT
For each test case, just print 'Yes' if PigVan can get bb after some operations; otherwise, print 'No'.
SAMPLE INPUT
261 6 9 4 2 0 7 -6 19 2 -6 641 2 3 4 4 2 1 3
SAMPLE OUTPUT
YesNo
SOLUTION
题解: (ai-1, ai, ai+1) -> (ai-1 + ai, -ai, ai + ai+1) .
他们前后的和不变,只是顺序不同,所以只需要判断前缀和是否相等
code:
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
	int a[100000],b[100000];
	
	int t,n;scanf("%d",&t);
	while(t--){
		scanf("%d",&n);
		a[0]=0;b[0]=0;
		for(int i=1;i<=n;i++){
			scanf("%d",&a[i]);
			a[i]+=a[i-1];
		}
		for(int i=1;i<=n;i++){
			scanf("%d",&b[i]);
			b[i]+=b[i-1];
		}
		sort(a+1,a+n+1);
		sort(b+1,b+n+1);
		int faut=1;
		for(int i=1;i<=n;i++)
		{
			if(a[i]!=b[i])
			faut=0;
		}
		if(faut==1) printf("Yes\n");
		else printf("No\n");
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值