zoukankan      html  css  js  c++  java
  • 2020-05-22 — 习题训练二

    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;
    }
     
  • 相关阅读:
    python虚拟环境--virtualenv
    python使用smtplib发送邮件
    python网络编程
    python操作MySQL数据库
    python面向对象
    python内置函数总结
    python异常处理
    python文件I/O
    python模块
    python函数
  • 原文地址:https://www.cnblogs.com/a-specter/p/12957361.html
Copyright © 2011-2022 走看看