Codeforces Round #720 (Div. 2) B. Nastia and a Good Array(1300)

Codeforces Round #720 (Div. 2) B. Nastia and a Good Array(1300)


Link

  • 1300 1300 1300构造卡了 1 1 1小时,题意在最多不超过 n n n次的操作下,每次操作选择两个下标不相等的数将 a [ l ] , a [ r ] a[l],a[r] a[l],a[r]变成 x , y x,y x,y其中 m i n ( x , y ) = = m i n ( a [ l ] , a [ r ] ) min(x,y)==min(a[l],a[r]) min(x,y)==min(a[l],a[r])。最终构造的数组中任意相邻数的 g c d = = 1 gcd==1 gcd==1
  • 思路:找到数组中最小数的下标,因为操作的时候不要求相邻,所以我们可以通过 n − 1 n-1 n1次操作(除去他本身下标),将其左右两边数进行构造。例如当前下标为 i d x idx idx的数构造值为 a b s ( i d x − p o s ) + a [ p o s ] abs(idx-pos)+a[pos] abs(idxpos)+a[pos],那么最终的数组就构造成了每相邻数的值差为 1 1 1,那么 g c d gcd gcd必然也为 1 1 1,总操作数 n − 1 n-1 n1同样符合要求。

代码:

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e5+10;
int a[N];
void solve(){
    int n;
    cin>>n;
    int ma=2e9;
    int pos;
    for(int i=1;i<=n;i++){cin>>a[i];if(ma>a[i]){ma=a[i],pos=i;};}//找到pos
    cout<<n-1<<endl;
    for(int i=1;i<=n;i++){
        if(i!=pos)
        cout<<pos<<' '<<i<<' '<<a[pos]<<' '<<abs(i-pos)+a[pos]<<endl;
    }
}
signed main(){
    int T=1;
    cin>>T;
    while(T--){
        solve();
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值