牛客周赛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;
}

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

相关推荐

  1. 51

    2024-07-19 02:20:01       23 阅读
  2. Round 51

    2024-07-19 02:20:01       20 阅读
  3. Round 51题解

    2024-07-19 02:20:01       19 阅读
  4. Round 50

    2024-07-19 02:20:01       36 阅读
  5. 26

    2024-07-19 02:20:01       52 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-19 02:20:01       67 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-19 02:20:01       72 阅读
  3. 在Django里面运行非项目文件

    2024-07-19 02:20:01       58 阅读
  4. Python语言-面向对象

    2024-07-19 02:20:01       69 阅读

热门阅读

  1. 开始构建我们自己的大语言模型:数据处理部分

    2024-07-19 02:20:01       21 阅读
  2. Vue.js(第一天)

    2024-07-19 02:20:01       21 阅读
  3. ThreadPoolExecutor拒绝策略

    2024-07-19 02:20:01       23 阅读
  4. Redis 散列

    2024-07-19 02:20:01       17 阅读
  5. C# —— HashTable

    2024-07-19 02:20:01       21 阅读
  6. 4 Ajax

    2024-07-19 02:20:01       19 阅读
  7. GNU/Linux - U-BOOT的GPIO command

    2024-07-19 02:20:01       18 阅读
  8. 一篇文章帮你彻底搞懂剩余运算符!!

    2024-07-19 02:20:01       19 阅读
  9. selenium 之 css定位

    2024-07-19 02:20:01       21 阅读
  10. Elasticsearch SQL:解锁Elasticsearch数据的新方式

    2024-07-19 02:20:01       24 阅读
  11. 力扣第十二题——整数转罗马数字

    2024-07-19 02:20:01       21 阅读
  12. Qt 实战(6)事件 | 6.3、自定义事件

    2024-07-19 02:20:01       24 阅读