牛客周赛51

小红同余

<A-小红的同余_牛客周赛 Round 51 (nowcoder.com)>

ac code

#include<iostream>
using namespace std;
int main(){
    int cnt=1;
    int m;cin>>m;
    while((1+cnt*m)%2!=0){
        //不能被整除,那么就不是整数x
        cnt++;
    }
    cout<<(1+cnt*m)/2;
    return 0;
}

小红三倍数

<B-小红的三倍数_牛客周赛 Round 51 (nowcoder.com)>

#include<iostream>
using namespace std;
int res=0;
int main(){
    int n;cin>>n;
    while(n--){
        string a;cin>>a;
        for(int i=0;i<a.length();i++){
            res+=a[i]-'0';//将所有位数相加
        }
    }
    if(res%3==0)cout<<"YES";
    else cout<<"NO";
    return 0;
}

前两题签到题,不在这里过多解释

小红充电

<C-小红充电_牛客周赛 Round 51 (nowcoder.com)>

/*不充电玩手机y
边冲边玩a
只充不玩b
t以下触发超级充电,每分钟冲c
现在手机x*/
#include<iostream>
using namespace std;
double res=1e18,res1;
int main(){
    int x,y,t,a,b,c;cin>>x>>y>>t>>a>>b>>c;
    int ans=100-x;
    if(x<=t){
        res=min((ans*1.0/c),res);
    }
    else {
        res=min((ans*1.0/b),res);
        //cout<<res<<endl;
        res1+=(double)(x-t)/y;
        //cout << (double)(x-t)/y;
        //cout << res1<<endl;
        res1+=(100-t)*1.0/c;
        //cout<<res1<<endl;
        res=min(res1,res);
    } 
    printf("%lf",res);
    return 0;
}

这题需要考虑在电量没有达到超级快充的时候,是否应该先进行耗电,在开始快速充电

小红的gcd

<D-小红的 gcd_牛客周赛 Round 51 (nowcoder.com)>

#include<iostream>
#include<algorithm>
#define int long long
using namespace std;
int res;
signed main(){
    string a;cin>>a;
    int b;cin>>b;
    for(int i=0;i<a.length();i++){
         res=res*10+a[i]-'0';
             res=res%b;
            //从左往右除,在字符串的基础上对他进行求
    }
    if(res==0)cout<<b;
    else{
        res=__gcd(res,b);
        cout<<res;
    }
    return 0;
}

这道题的问点就是字符串对于整形的求余,那么就可以用字符串的形式开始循环,实现大整数的求余,这题降低了难度,只有一个大整数,两个大整数那么就需要用高精度

  • 7
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

shix .

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值