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;
}

 

posted @ 2019-02-16 22:38  raincle  阅读(123)  评论(0编辑  收藏  举报