A题看数据很水直接暴力一遍,

#include<iostream>
using namespace std;
#define LL long long
int main()
{
    int k,l,m,n,d,ans=0;
    cin>>k>>l>>m>>n>>d;
    for(int i=1;i<=d;i++)
    {
        if(i%k==0||i%l==0||i%m==0||i%n==0)ans++;
    }
    cout<<ans<<endl;
}
View Code

B题数据也很小,直接模拟他们要走的过程,不过要注意龙可能在不到一小时的时间就追上公主,所以要用double代码:

#include<iostream>
using namespace std;
#define LL long long
int main()
{
    double vp,vd,t,f,c;
    cin>>vp>>vd>>t>>f>>c;
    double n1=t*vp,n2=0;
    int ans=0;
    if(vp>vd)
    {
        cout<<0<<endl;
        return 0;
    }
    while(1)
    {
        if(n1>=c)break;    
        double ti=n1/(vd-vp);
        //cout<<n1<<" "<<ti<<" "<<ans<<endl;
        if(ti*vp+n1>=c)
        {
            //cout<<ti*vp+n1;
            break;
        }
        else
        {
            ans++;
            n1=ti*vp+n1;
            n1=n1+(ti+f)*vp;
        }
        
    }
    cout<<ans<<endl;
}
View Code

C题,如果b!=0就从2开始,记录sum和max每一次b>0都输出max+1,b=0之后再输出a遍max+1,其余的就输出max就行,注意b=0的情况,代码:

#include<bits/stdc++.h>
using namespace std;
vector<int>ans;
int main()
{
    ans.clear();
    int n,a,b;
    cin>>n>>a>>b;
    if(a+b+1>n)
    {
        cout<<-1<<endl;
        return 0;
        
    }
    if(b==0)
    {
        if(a==0)
        {
            for(int i=0;i<n;i++)ans.push_back(15);
            
        }
        else if(a==n-1)
        {
            cout<<-1<<endl;
            return 0;
        }
        else
        {
            int sum=15,max=15,now=15;
            ans.push_back(15);
            ans.push_back(15);
            for(int i=2;i<n;i++)
            {
                
                if(a!=0)
                {
                    ans.push_back(max+1);
                    //cout<<" "<<max+1;
                    max=max+1;
                    a=a-1;
                }
                else
                {
                    ans.push_back(max);
                    //cout<<" "<<max;
                }
            }
        }    
    }
    else
    {
        int sum=2,max=2;
        ans.push_back(2);
        for(int i=1;i<n;i++)
        {
            if(b!=0)
            {
                ans.push_back(sum+1);
                
                //cout<<" "<<sum+1;
                max=sum+1;
                sum=sum+sum+1;
                b--;
            }
            else if(a!=0)
            {
                ans.push_back(max+1);
                
                //cout<<" "<<max+1;
                max=max+1;
                a=a-1;
            }
            else
            {
                ans.push_back(max);
                
                //cout<<" "<<max;
            }
        }
        
    }
    if(a!=0||b!=0)cout<<-1<<endl;
    else
    {
        for(int i=0;i<ans.size();i++)cout<<ans[i]<<" ";
        
     } 

}
View Code

 

posted on 2020-12-20 22:30  小灰灰的父亲  阅读(77)  评论(0编辑  收藏  举报