Codeforces Round #720 (Div. 2)

题目传送门:
codeforces #720(div2)

A. Nastia and Nearly Good Numbers

AC Code

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        LL a,b;
        scanf("%lld%lld",&a,&b);
        if(b==1) printf("NO\n");
        else
        {
            printf("YES\n");
            if(b==2) printf("%lld %lld %lld\n",a,3*a,4*a);
            else printf("%lld %lld %lld\n",a,(b-1)*a,b*a);
        }
    }
    //system("pause");
    return 0;
}

B. Nastia and a Good Array

思路:

看到这个题目首先想到的就是x和x+1肯定是互质的。那么我们只需要把最小的数调到最前面,然后构造相邻的数都相差1即可。操作的次数最多为n次。

AC Code

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int a[N];
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n;
        scanf("%d",&n);
        int idx=0,minn=1e9+10;
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
            if(a[i]<minn)
            {
                minn=a[i];
                idx=i;
            }
        }
        if(idx!=1)
        {
            printf("%d\n",n);
            printf("%d %d %d %d\n",1,idx,minn,a[1]);
            a[idx]=a[1];
            a[1]=minn;
        }
        else printf("%d\n",n-1);
        for(int i=2;i<=n;i++)
            printf("%d %d %d %d\n",1,i,minn,minn+i-1);
    }
    //system("pause");
    return 0;
}

C. Nastia and a Hidden Permutation

思路:

这是一个交互题,我们观察可以得到,如果你知道了1的位置,那么你使用操作2且使x为1,你就可以知道其他每一个位置的数,这里需要操作n次。那么问题就转化为如何在n/2+30次之内找到1的位置。那么我们就可以使用1操作使x为n-1,每次找两个相邻位置i和i+1,如果1在i位置上,那么答案就会返回1,那么就找到了。但是如果1在i+1位置上那么答案是2,如果2在i+1位置上答案还是2。那么我们该怎么确认这个位置到底是1还是2呢,其实只要反过来再操作一次即可。具体细节看代码。

AC Code

#include<bits/stdc++.h>
using namespace std;
const int N=1e4+10;
int p[N];
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n;
        scanf("%d",&n);
        int pos=n;  //找到1的位置
        for(int i=1;i+1<=n;i=i+2)
        {
            int x;
            printf("? %d %d %d %d\n",2,i,i+1,1);
            fflush(stdout);
            scanf("%d",&x);
            if(x==1)
            {
                p[i]=1;
                pos=i;
                break;
            }
            else if(x==2)
            {
                printf("? %d %d %d %d\n",2,i+1,i,1);
                fflush(stdout);
                scanf("%d",&x);
                if(x==1)
                {
                    p[i+1]=1;
                    pos=i+1;
                    break;
                }
            }
        }
        p[pos]=1;
        for(int i=1;i<=n;i++)
        {
            int x;
            if(i==pos) continue;
            printf("? %d %d %d %d\n",1,pos,i,n-1);
            fflush(stdout);
            scanf("%d",&x);
            p[i]=x;
        }
        printf("! ");
        for(int i=1;i<=n;i++) printf("%d ",p[i]);
        printf("\n");
        fflush(stdout);
    }
    //system("pause");
    return 0;
}
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值