【玲珑杯R7 A】Boring Game

Submissions:587Solved:182

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
T
T, indicating the number of test cases.

For each test case:

In the first line, there are only one integer
n
n(n≤105), indicating the number of food piles.

The second line is
n
n integers indicate sequence
a
a ( | ai | ≤ 106).

The third line is
n
n integers indicate sequence
b
b ( | bi | ≤ 106).
OUTPUT
For each test case, just print ‘Yes’ if PigVan can get
b
b after some operations; otherwise, print ‘No’.
SAMPLE INPUT
2
6
1 6 9 4 2 0
7 -6 19 2 -6 6
4
1 2 3 4
4 2 1 3
SAMPLE OUTPUT
Yes
No

【题目链接】:http://www.ifrog.cc/acm/problem/1071?contest=1009&no=0

【题解】

对第i个位置进行操作的话
假设为
a[i-1],a[i],a[i+1]
则变为
a[i-1]+a[i],-a[i],a[i]+a[i+1];
可以看一下前缀和

s[i-1],s[i],s[i+1]
变成了
s[i],s[i-1],s[i+1];
即每次操作只会交换相邻的两个数位置的前缀和;
则处理出a数组的前缀和和b数组的前缀和
看看它们所含的元素、以及元素的个数是否相等(集合的相等)
这个用multiset就能搞;当然用map也行。
或者排个序判断;

【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%lld",&x)

typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

const int MAXN = 1e5+100;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);

int T,n;
LL sum1[MAXN],sum2[MAXN],x;
multiset <LL> myset;

int main()
{
    //freopen("F:\\rush.txt","r",stdin);
    rei(T);
    while (T--)
    {
        myset.clear();
        rei(n);
        rep1(i,1,n)
        {
            rel(x);
            sum1[i] = sum1[i-1]+x;
            myset.insert(sum1[i]);
        }
        rep1(i,1,n)
        {
            rel(x);
            sum2[i] = sum2[i-1]+x;
            __typeof(myset.begin()) bo = myset.find(sum2[i]);
            if (bo!=myset.end())
                myset.erase(bo);
        }
        if (!myset.empty())
            puts("No");
        else
            puts("Yes");
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 要在 BoringSSL 中设置随机数,你可以使用 `RAND_set_rand_method` 函数来设置随机数生成器的实现。这个函数需要一个指向 `RAND_METHOD` 结构体的指针,这个结构体包含了用于生成、清除和添加随机数种子的函数。你可以使用 BoringSSL 提供的默认实现,也可以自己实现这个结构体来提供自定义的随机数生成方式。 示例代码如下: ``` #include <openssl/rand.h> RAND_METHOD fake_rand_method; int fake_rand_bytes(unsigned char *buf, int num) { // 在这里实现生成 num 个字节的随机数的逻辑 return 1; } void fake_rand_cleanup(void) { // 在这里实现清除随机数种子的逻辑 } int fake_rand_add(const void *buf, int num, double entropy) { // 在这里实现添加随机数种子的逻辑 return 1; } int fake_rand_status(void) { // 在这里实现返回随机数生成器的状态的逻辑 return 1; } int main() { fake_rand_method.bytes = fake_rand_bytes; fake_rand_method.cleanup = fake_rand_cleanup; fake_rand_method.add = fake_rand_add; fake_rand_method.status = fake_rand_status; RAND_set_rand_method(&fake_rand_method); // 现在 BoringSSL 会使用 fake_rand_method 中定义的函数来生成随机数 return 0; } ``` 注意,如果你使用的是 BoringSSL 的 C++ 封装(也就是 `boringssl::RAND` 类),那么你可以 ### 回答2: boringssl是一个用于加密和安全传输的开源软件库,其随机数的设置是非常重要的。 在boringssl中,可以通过以下步骤来设置随机数: 1. 初始化随机数引擎:首先,需要使用一个随机数引擎来生成随机数。boringssl使用Crypto::Rand类来生成随机数,可以通过调用Crypto::Rand::Init()函数来初始化随机数引擎。 2. 获取随机数:一旦随机数引擎被初始化,可以使用Crypto::Rand::Bytes()函数来获取指定长度的随机数。该函数将生成的随机数存储在指定的内存位置中。 3. 设置随机数回调函数:为了更好地控制随机数的生成过程,boringssl还提供了设置随机数回调函数的功能。可以通过调用CRYPTO_set_rand_bytes_callback()函数来设置随机数回调函数,该函数接受一个函数指针作为参数,用于指定随机数的生成方式。 通过以上步骤,可以在boringssl中设置随机数。这样做是为了确保加密算法中使用的随机数具有足够的随机性和安全性,以提高加密和安全传输的效果。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值