首页 > 其他 > 详细

2020-05-22 — 习题训练二申请代付

时间:2020-05-25 16:44:41      阅读:49      评论:0      收藏:0      [点我收藏+]

A - Candies

给定一个n,输出满足 x+2x+4x+...+2^(k-1)x=n 的x,根据等比数列前n项和的公式,while循环找判断个式子是否成立

#include <iostream>
#include <string>
#include <vector>
#include <cstdio>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,x=3;
        cin>>n;
        while(n%x!=0)
        {
            x=1+2*x;
        }
        cout<<n/x<<endl;
    }
    return 0;
}

B - Balanced Array

构造一个长度为n,满足前一半为偶数,后一半奇数,前一半后一半和相等,把它们分成四个一组,两个奇数两个偶数,让他们和相等

int main()
{
    int n,i,j;
    cin>>n;
    while(n--){
        int x;
        cin>>x;
        if(x%4==0){
            cout<<"YES"<<endl;
            int j=2;
            for(i=0;i<x/4;i++){
                cout<<j<<" ";
                j=j+2;
                cout<<j<<" ";
                j=j+4;
            }
            j=1;
            for(i=0;i<x/4;i++){
                cout<<j<<" ";
                j=j+4;
                cout<<j<<" ";
                j=j+2;
            }
            cout<<endl;
        }else{
            cout<<"NO"<<endl;
        }
    }
    return 0;
}

C - Ichihime and Triangle

技术分享图片

 

输入a<=b<=c<=d;寻找a<=x<=b,b<=y<=cc<=z<=d,使x,y,z可以构成三角形,

输出bcc就行啦

 

int main()
{
    int n,i,j;
    cin>>n;
    while(n--){
        int a,b,c,d;
        cin>>a>>b>>c>>d;
        cout<<b<<" "<<c<<" "<<c<<endl;

    }
    return 0;
}

 

D - Kana and Dragon Quest game

输入三个数,x,m,n;打小怪兽,小怪兽有x滴血,可以放m次一技能Void Absorption,x=x/2+10;可以放n次2技能,x-=10;

先放一技能,再放二技能,计算能不能把怪兽打死

技术分享图片

 

int main()
{
    int n,i,j;
    cin>>n;
    while(n--)
    {
        int a,b,c,d;
        cin>>a>>b>>c;
        while(b&&(a/2+10)<a)
        {
            a=(a/2+10);
            b--;
        }
        a-=c*10;
        if(a>0)
            cout<<"NO"<<endl;
        else
            cout<<"YES"<<endl;
    }
    return 0;
}

E - Candies and Two Sisters

分糖果给两个姐妹,a+b=n;a<b;输出有多少种分配方法;

当n为偶数的时候,n/2-1,(a可以取1到n/2-1

当n为奇数的时候,n/2,(a可以取1到n/2

int main()
{
    int n,i,j;
    cin>>n;
    while(n--)
    {
        int a,b,c,d;
        cin>>a>>b>>c;
        while(b&&(a/2+10)<a)
        {
            a=(a/2+10);
            b--;
        }
        a-=c*10;
        if(a>0)
            cout<<"NO"<<endl;
        else
            cout<<"YES"<<endl;
    }
    return 0;
}

 

F - Construct the String

 打印长度为N的字符串,每个长度为b,每个长度为a的子字符串恰好有b;

循环着输出b种字母;

int main()
{
    int n,i,j;
    cin>>n;
    while(n--)
    {
        int a,b,c;
        cin>>a>>b>>c;
        for(i=0;i<a;i++){
            j=i%c;
            printf("%c",a+j);
        }
        cout<<endl;

    }
    return 0;
}

 

 

 

2020-05-22 — 习题训练二申请代付

原文:https://www.cnblogs.com/a-specter/p/12957361.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!