(cf补题+思维)Codeforces Round #808 (Div. 2)A--C

 A. Difference Operations

读完第一题我就有点傻了,有点思路却无从下手的感觉

A. Difference Operations

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given an array aa consisting of nn positive integers.

You are allowed to perform this operation any number of times (possibly, zero):

  • choose an index ii (2≤i≤n2≤i≤n), and change aiai to ai−ai−1ai−ai−1.

Is it possible to make ai=0ai=0 for all 2≤i≤n2≤i≤n?

Input

The input consists of multiple test cases. The first line contains a single integer tt (1≤t≤1001≤t≤100)  — the number of test cases. The description of the test cases follows.

The first line contains one integer nn (2≤n≤1002≤n≤100) — the length of array aa.

The second line contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109).

Output

For each test case, print "YES" (without quotes), if it is possible to change aiai to 00 for all 2≤i≤n2≤i≤n, and "NO" (without quotes) otherwise.

You can print letters in any case (upper or lower).

Example

input

Copy

4
2
5 10
3
1 2 3
4
1 1 1 1
9
9 9 8 2 4 4 3 5 3

output

Copy

YES
YES
YES
NO

题意:给你一个数组,可以进行无数次将a[i]=a[i]-a[i-1]的操作,问是否能将出了a[1]以外的所有数都变成0;

思路:我们从前往后推会发现,如果a[2]想要变成0的话,a[2]的变化来自a[1],所以只有a[2]是a[1]的倍数的时候,a[2]才能变成零,同时a[3]也必须是a[1]的倍数,所以答案就呼之欲出了。

代码略,因为我用的是gcd的方法写的,但是不太好理解,这里就不放了。

B. Difference of GCDs

B题真是吃了大亏,我以为构造的数组不能有重复的,所以绞尽脑汁的不会,结果发现题目里面根本没说。

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given three integers nn, ll, and rr. You need to construct an array a1,a2,…,ana1,a2,…,an (l≤ai≤rl≤ai≤r) such that gcd(i,ai)gcd(i,ai) are all distinct or report there's no solution.

Here gcd(x,y)gcd(x,y) denotes the greatest common divisor (GCD) of integers xx and yy.

Input

The input consists of multiple test cases. The first line contains a single integer tt (1≤t≤1041≤t≤104) — the number of test cases. The description of the test cases follows.

The first line contains three integers nn, ll, rr (1≤n≤1051≤n≤105, 1≤l≤r≤1091≤l≤r≤109).

It is guaranteed that the sum of nn over all test cases does not exceed 105105.

Output

For each test case, if there is no solution, print "NO" (without quotes). You can print letters in any case (upper or lower).

Otherwise, print "YES" (without quotes). In the next line, print nn integers a1,a2,…,ana1,a2,…,an — the array you construct.

If there are multiple solutions, you may output any.

Example

input

Copy

4
5 1 5
9 1000 2000
10 30 35
1 1000000000 1000000000

output

Copy

YES
1 2 3 4 5
YES
1145 1926 1440 1220 1230 1350 1001 1000 1233
NO
YES
1000000000

题意:构造一个数组a,让每个gcd(i,a[i])都不相同。

脑筋急转弯,只要让每个a[i]是i的倍数,gcd(i,a[i])就都是i了,肯定不相同,所以我们就是要找每个i是否在区间内有倍数就行;

#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
queue<long long int> q;
int main()
{
    ll t,i,n,l,r,k;
    ll a[100010];
    scanf("%lld",&t);
    while(t--)
    {
        scanf("%lld %lld %lld",&n,&l,&r);
        for(i=1;i<=n;i++)
        {
            k=r/i*i;//关键公式
            if(k<l)
            {
                break;
            }
            else a[i]=k;
        }
        if(i<=n)
        {
            printf("NO\n");
        }
        else
        {
            printf("YES\n");
            for(i=1;i<=n;i++)
            {
                printf("%lld ",a[i]);
            }
            printf("\n");
        }
    }
    return 0;
}

C. Doremy's IQ

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Doremy is asked to test nn contests. Contest ii can only be tested on day ii. The difficulty of contest ii is aiai. Initially, Doremy's IQ is qq. On day ii Doremy will choose whether to test contest ii or not. She can only test a contest if her current IQ is strictly greater than 00.

If Doremy chooses to test contest ii on day ii, the following happens:

  • if ai>qai>q, Doremy will feel she is not wise enough, so qq decreases by 11;
  • otherwise, nothing changes.

If she chooses not to test a contest, nothing changes.

Doremy wants to test as many contests as possible. Please give Doremy a solution.

Input

The input consists of multiple test cases. The first line contains a single integer tt (1≤t≤1041≤t≤104) — the number of test cases. The description of the test cases follows.

The first line contains two integers nn and qq (1≤n≤1051≤n≤105, 1≤q≤1091≤q≤109) — the number of contests and Doremy's IQ in the beginning.

The second line contains nn integers a1,a2,⋯,ana1,a2,⋯,an (1≤ai≤1091≤ai≤109) — the difficulty of each contest.

It is guaranteed that the sum of nn over all test cases does not exceed 105105.

Output

For each test case, you need to output a binary string ss, where si=1si=1 if Doremy should choose to test contest ii, and si=0si=0 otherwise. The number of ones in the string should be maximum possible, and she should never test a contest when her IQ is zero or less.

If there are multiple solutions, you may output any.

Example

input

Copy

5
1 1
1
2 1
1 2
3 1
1 2 1
4 2
1 4 3 1
5 2
5 1 2 4 3

output

Copy

1
11
110
1110
01111

Note

In the first test case, Doremy tests the only contest. Her IQ doesn't decrease.

In the second test case, Doremy tests both contests. Her IQ decreases by 11 after testing contest 22.

In the third test case, Doremy tests contest 11 and 22. Her IQ decreases to 00 after testing contest 22, so she can't test contest 33.

逆着推,先让k等于0,因为贪心策略当我们运行的结尾没有浪费是最好的情况,然后到着推,如果k<a[i],k就++,注意判断k要一直小于q;

#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
queue<long long int> q;
int main()
{
    ll t,n,q,a[100010],k,i;
    int vis[100010];
 
    scanf("%lld",&t);
    while(t--)
    {
        memset(vis,0,sizeof(vis));
        scanf("%lld %lld",&n,&q);
        for(i=1;i<=n;i++)
        {
            scanf("%lld",&a[i]);
        }
        k=0;
        for(i=n;i>=1;i--)
        {
            if(k<a[i])
            {
                k++;
                if(k<=q)
                vis[i]=1;
                else
                k--;
            }
            else if(k<=q)
            {
                vis[i]=1;
            }
        }
        for(i=1;i<=n;i++)
        {
            if(vis[i]==1)
                printf("1");
            else
                printf("0");
        }
        printf("\n");
    }
    return 0;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值