Codeforces Round #434 (Div. 2)

本文解析了三道算法题目,包括求特定后缀的最小倍数、确定房间所在楼层及检查单词拼写错误。提供了清晰的思路说明与完整的代码实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

传送门

A题:求n的倍数的且后缀有k个0的最小的数

思路:通过一些结论我们知道2*5会得到一个后缀0,所以我们求一下这个说有多少个因子2和多少个因子5就行了,个数不够k的补够,多的不用管,然后再乘上增加的因子2和因子5就是结果了

代码如下:

#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
ll n,k;
ll solve(){
    ll c5 = 0;
    ll c2 = 0;//记录因子2和因子5的个数
    ll x = n;
    while(n % 5 == 0){
        c5++;
        n /= 5;
    }
    while(n % 2 == 0){
        c2++;
        n /= 2;
    }
    ll a5 = 0,a2 = 0;//需要补得因子个数
    if(c5 < k){
        a5 = k-c5;
    }
    if(c2 < k){
        a2 = k - c2;
    }
    for(int i=1;i<=a5;i++)
        x = x*5;
    for(int i=1;i<=a2;i++)
        x = x*2;
    return x;
}

int main(void){
    cin >> n >> k;
    cout << solve() << endl;


    return 0;
}

B题:一栋房子每一个房间都有一个编号,从小到大的,Polycarp不知道每一层有多少间房子,但他记得一些编号房间的层数,然后问你能不能确定编号为n的房间是在第几层

思路:这题比赛时犯傻没写出来,由于数据范围比较小,可以直接枚举每层的房间数,从1到100,看一下有多少符合的,如果这些符合的每层房间数,能够唯一确定n所在的层数,那么就输出n所在层数,不能就输出-1

代码如下:







#include<iostream>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
const int MAX =  110;
int a[MAX],n,m,top;
struct node{
    int k,f;
}q[MAX];
bool isok(int x){//判断每层x个房间是否可以
    for(int i=1;i<=m;i++){//判断记忆中的是否全部符合
        int floor = q[i].k %x == 0? q[i].k/x:q[i].k/x+1;//这个编号的层数
        if(floor != q[i].f)
            return false;
    }
    return true;
}
int main(void){
    scanf("%d %d",&n,&m);
    for(int i=1;i<=m;i++){
        scanf("%d %d",&q[i].k,&q[i].f);
    }
    for(int i=1;i<=100;i++){
        if(isok(i)){
            a[++top] = i;
        }
    }
    map<int,int> mp;//记录得到n的层数是否唯一
    for(int i=1;i<=top;i++){
        int floor = n%a[i] == 0? n/a[i]:n/a[i]+1;
        mp[floor]++;
    }
    if(mp.size() == 1){
        printf("%d\n",(int)(mp.begin()->first));
    }
    else
        printf("%d\n",-1);
    return 0;
}

C题:判断一个单词是否发生拼写错误,在错误点将其隔开,一个辅音块如果有三个不同的辅音或者是三个以上的辅音且有两个不同的辅音即视为错误,辅音块就是一段连续的辅音。
思路:直接模拟就行了,用map标记一下辅音块,记得要清除

代码如下:

#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<vector>
#include<algorithm>
#include<map>
#include<set>

using namespace std;

map<char,int> mp;
bool isok(char ch){//判断是否为辅音
    if(ch == 'a' || ch == 'e' || ch == 'i')
        return false;
    if(ch == 'o' || ch == 'u')
        return false;

    return true;
}

int main(void){
    string str;
    cin >> str;
    int len = (int)str.length();
    int sum = 0;
    for(int i=0;i<len;i++){
        bool isfind = false;
        if(isok(str[i])){
            mp[str[i]]++;
            sum++;
            if(mp.size() == 3){//一个辅音块出现了三个不同的辅音
                cout << " ";
                isfind = true;
                mp.clear();
                sum = 0;
            }
            else if(mp.size() == 2 && sum >= 3){//出现了三个以上的辅音,且有两个不同的辅音
                cout << " ";
                isfind = true;
                mp.clear();
                sum = 0;
            }
        }
        else{//清空上一个辅音块
            mp.clear();
            sum = 0;
        }
        cout << str[i];
        if(isfind){//因为当前这个辅音被清除,所以这里添加进去
            mp[str[i]]++;
            sum++;
        }
    }

    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值