• 题意:商店里有\(k\)个包裹,第\(i\)个包裹中含有\(i\)个物品,现在想要买\(n\)物品,你可以选择某一个包裹购买任意次,使得物品数刚好等于\(n\),求最少的购买次数.

  • 题解:首先,假如\(k\ge n\),那么只用买一次.否则,我们枚举\(1\)~\(\sqrt n\),若\(n\ mod\ i=0\):

    ​ 1.\(n/i\le k\),那么\(i\)一定是我们所需要的最小购买次数,

    ​ 2.\(n/i>k\),只要\(i\le k\),我们就维护\(ans\)和\(n/i\)的最小值.

    ​ 纸上谈来终觉浅,要自己去好好思考,对数字敏感一点,也就想出来了.

  • 代码:

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    #include <stack>
    #include <queue>
    #include <vector>
    #include <map>
    #include <set>
    #include <unordered_set>
    #include <unordered_map>
    #define ll long long
    #define fi first
    #define se second
    #define pb push_back
    #define me memset
    const int N = 1e6 + 10;
    const int mod = 1e9 + 7;
    const int INF = 0x3f3f3f3f;
    using namespace std;
    typedef pair<int,int> PII;
    typedef pair<ll,ll> PLL; int t;
    ll n,k; int main() {
    ios::sync_with_stdio(false);cin.tie(0);
    cin>>t;
    while(t--){
    cin>>n>>k;
    if(n<=k){
    printf("1\n");
    }
    else{
    bool ok=0;
    ll ans=INF;
    for(ll i=1;i*i<=n;++i){
    if(n%i==0){
    if(n/i<=k){
    ok=1;
    ans=i;
    break;
    }
    else{
    if(i<=k){
    ans=min(ans,n/i);
    }
    }
    }
    }
    printf("%lld\n",ans);
    } } return 0;
    }

Codeforces Round #644 (Div. 3) D. Buying Shovels (数学)的更多相关文章

  1. Codeforces Round #644 (Div. 3)

    比赛链接:https://codeforces.com/contest/1360 A - Minimal Square 题意 计算能包含两个 $a \times b$ 矩形的最小正方形的面积. 题解 ...

  2. [每日一题2020.06.11]Codeforces Round #644 (Div. 3) H

    A-E见 : 这里 题目 我觉得很有必要把H拿出来单独发( 其实是今天懒得写题了 ) problem H 一个从 1 到 $ 2^m - 1$ 的长度为m的连续二进制序列, 删去指定的n个数, 问剩余 ...

  3. [每日一题2020.06.10]Codeforces Round #644 (Div. 3) ABCDEFG

    花了5个多少小时总算把div3打通一次( 题目链接 problem A 题意 : 两个x*y的矩形不能重叠摆放, 要放进一个正方形正方形边长最小为多少 先求n = min(2x, 2y, x+y) 再 ...

  4. Codeforces Round #180 (Div. 2) C. Parity Game 数学

    C. Parity Game 题目连接: http://www.codeforces.com/contest/298/problem/C Description You are fishing wit ...

  5. Codeforces Round #188 (Div. 2) C. Perfect Pair 数学

    B. Strings of Power Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/318/p ...

  6. Codeforces Round #274 (Div. 1) B. Long Jumps 数学

    B. Long Jumps Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/480/problem/ ...

  7. Codeforces Round #200 (Div. 1)A. Rational Resistance 数学

    A. Rational Resistance Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/343 ...

  8. Codeforces Round #369 (Div. 2) D. Directed Roads 数学

    D. Directed Roads 题目连接: http://www.codeforces.com/contest/711/problem/D Description ZS the Coder and ...

  9. Codeforces Round #368 (Div. 2) C. Pythagorean Triples 数学

    C. Pythagorean Triples 题目连接: http://www.codeforces.com/contest/707/problem/C Description Katya studi ...

随机推荐

  1. Python_列表(list)

    list()类中的提供的操作 1.索引取值 li = [11,22,33,44,55] v1 = li[3] print(li[2]) #索引取出33 print(v1) #索引取出44 print( ...

  2. CWE 4.3:强化你的数据自我保护能力

    摘要:如何通过软件自动的检查法规中涉及的数据保护, 新版的CWE 4.3 给出了一个解决途径. 1. 按照惯例,先说故事 用12月初在深圳参加的"全球C++及系统软件技术大会"里C ...

  3. pandas的级联操作

    级联操作 pd.concat, pd.append import pandas as pd from pandas import DataFrame import numpy as np pandas ...

  4. CNN可视化技术总结(一)--特征图可视化

    导言: 在CV很多方向所谓改进模型,改进网络,都是在按照人的主观思想在改进,常常在说CNN的本质是提取特征,但并不知道它提取了什么特征,哪些区域对于识别真正起作用,也不知道网络是根据什么得出了分类结果 ...

  5. winform 窗体中顶部标题居中显示

    在网上看了很多例子,都不能居中,都有或多或少的问题 自己根据网友的代码改编入下: 先确随便写一个标题的内容: string titleMsg ="Winfrom Title" 获取 ...

  6. Django--虛擬環境Virtualenv的安裝使用

    Django--虛擬環境Virtualenv的安裝使用 本次隨筆只要記錄在windows下安裝virtualenvwrapper,以及簡單的使用命令. virtualenvwrapper的安裝     ...

  7. Windows Server 2012 R2 英文版汉化安装中文语言包教程更改为中文版

    是这样的,一台海外的windows机器默认是英文版的,但是特别费劲用起来,就更改为中文版,因为海外的供应商并不提供中文版镜像. 1.首先打开控制面板,找到add language,拉到底就是有中文,很 ...

  8. Service Mesh架构的持续演进 单体模块化 SOA 微服务 Service Mesh

    架构不止-严选Service Mesh架构的持续演进 网易严选 王育松 严选技术团队 2019-11-25 前言同严选的业务一样,在下层承载它的IT系统架构一样要生存.呼吸.增长和发展,否则过时的.僵 ...

  9. Spring Cloud 2020.0.1 正式发布!真是头疼。。。

    上一篇:Spring Cloud 2020.0.0 正式发布,全新颠覆性版本! 号外!号外!号外! Spring Cloud 2020.0.0 在去年 12 月底,赶在一年的尾巴最后几天仓促发布了,时 ...

  10. Spring整合SpringMVC + Mybatis基础框架的配置文件

    目录 前言 1. Mybatis层编写 2. Spring层编写 1. Spring整合Mybatis 2. Spring整合service 3. SpringMVC层编写 1. 编写web.xml ...