Codeforces Round 951 (Div. 2) abc

a//https://codeforces.com/contest/1979/problem/A 签到

#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
const int N = 5E4 + 10;
int a[N],t;

int main()
{
    cin >> t;
    while(t --)
    {
        int n;cin >> n;
        int ans = 1e9 + 10;
        for(int i = 1;i <= n;i ++)
            cin >> a[i];
        for(int i = 1;i < n;i ++)
            ans = min(max(a[i],a[i + 1]),ans);
        cout << ans - 1 << endl;
    }
    return 0;
}


b// https://codeforces.com/contest/1979/problem/B 要求输出最大公共子序列 ——> 从最小到最大 ——> 当m xor x == n xor y当m== x,n == y时
//此时取最小的数值0,要保证一直满足上述等式 ——> 需要m和n的每一项二进制数同时改变或者同时不变 ——> 即从最低项开始x,y的相同项k,答案即为2^k
//也就是说答案为x^y的lowbit

#include<iostream>
using namespace std;

void solve()
{
    int x,y;cin >> x >> y;
    x ^= y;
    cout << (x&-x) << endl;
}

int main()
{
    int t;cin >> t;
    while(t --)
        solve();
    return 0;
}


c//https://codeforces.com/contest/1979/problem/C 构造题,给定一个数组k要求求出一个数组b满足b的求和等于bi*ki
//我们假定b的和即收获总硬币数为k的最小公倍数,即当b/ki的和 < 收获总硬币数时满足,否则输出-1

#include<iostream>
using namespace std;
const int N = 2E5 + 10;
long long k[N],b[N];

long long gcd(long long x,long long y)
{
    return x%y == 0?y:gcd(y,x%y);
}

long long lcm(long long x,long long y)
{
    return x*y/gcd(x,y);
}

void solve()
{
    int n;cin >> n;
    long long ans = 1;
    for(int i = 1;i <= n;i ++)
    {
        cin >> k[i];
        ans = lcm(ans,k[i]);
    }
    long long s = 0;
    for(int i = 1;i <= n;i ++)
    {
        b[i] = ans / k[i];
        s += b[i];
    }
    if(s >= ans)cout << "-1" << endl;
    else{
        for(int i = 1;i <= n;i ++)
            cout << b[i] << ' ';
        cout << endl;
    }
}

int main()
{
    int t;cin >> t;
    while(t --)
        solve();
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值