山东省第七届ACM大学生程序设计竞赛 A题 Julyed

本文解析了一个简单的算法问题:如何计算给定数量单词在特定条件下所需的最少背诵天数。通过几个具体例子说明了算法实现的过程,并给出了简洁的C++代码实现。

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

题意:

有n个单词,每天这个人可以背m个,问你最少几天可以背完,签到题

分析:

input
5
6 3
2 1
1 2
5 2
4 3
Output
2
2
1
3
2

分析几个案例:
第一个案例:6个单词,每天可以背3个,两天可以背完
第三个案例:1个单词,每天可以背2个,一天可以背完
第四个案例:5个单词,每天可以背2个,三天可以背完

代码:

#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <set>
#include <algorithm>
#include <queue>
#include <map>
#define ll long long;
#define debug cout<<"********"<<endl;
using namespace std;
const int maxn = 1e9+5;
const int mod = 1e9+7;
int main(){
    std::ios::sync_with_stdio(false);
    int T;cin>>T;
    while(T--){
        int a,b;
        cin>>a>>b;
        if(a < b){
            cout<<1<<endl;
        }
        else{
            int c = a / b;
            if(c * b >= a){
                cout<<c<<endl;
            }else{
            cout<<c+1<<endl;}
        }
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值