Codeforces #529.div3

A

#include <iostream>

using namespace std;

int main()
{
    char str1[100],str2[100];
    int n,i,a=1,t=0;
    cin>>n>>str1;
    for(i=0;i<n;i+=a)
    {
        str2[t++]=str1[i];
        a++;
    }
    str2[t++]='\0';
    cout<<str2<<endl;
    return 0;
}

B

#include <bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
int a[maxn];
int main()
{
    int n,i;
    cin>>n;
    for(i=0;i<n;i++)cin>>a[i];
    sort(a,a+n);
    cout<<min(a[n-2]-a[0],a[n-1]-a[1])<<endl;
    return 0;
}

C

#include <bits/stdc++.h>
using namespace std;
const int maxn=2e5+100;
int num[maxn];
int lis[maxn];
void init()
{
    lis[0]=1;
    int t=1,a=2;
    while(a<=1e9+10)
    {
        lis[t++]=a;
        a<<=1;
    }
}
int main()
{
    int n,k;
    cin>>n>>k;
    if(k>n)cout<<"NO"<<endl;
    else
    {
        init();
        int d=0;
        while(k>0)
        {
            int b;
            for(b=0;lis[b]<n;b++);
            if(lis[b]>n)b--;
            while((n-pow(2,b))<k-1)
                  {
                      b--;
                  }
            n=n-pow(2,b);
            num[d++]=pow(2,b);
            k--;
        }
        if(n==0)
        {
            cout<<"YES"<<endl;
            for(int i=d-1;i>=0;i--)cout<<num[i]<<' ';
            cout<<endl;
        }
        else cout<<"NO"<<endl;
    }
    return 0;
}

 

转载于:https://www.cnblogs.com/raincle/p/10389591.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值