题解 CF1011B Planning The Expedition
Solution
考虑 二分 。
首先要确定二分的对象,显然二分天数较为简单。
每次找到的 \(mid\) 需要判断是否能让整队人吃饱,那就调用一个 check()
。
对于 check()
,求出每包食物可供的人数,相加后与 \(n\) 相比较。
具体操作见下。
Code
#include<iostream>
using namespace std;
#define ll long long
#define max(x,y) x>y?x:y
ll n,m,l=1,r,a[1005],q[100005],d,o,mid,b;
inline bool check(int x)
{
ll t=0;
for(int i=1;i<=d;++i)
t+=q[i]/x;
return t>=n;
}
int main()
{
ios::sync_with_stdio(false);
cin>>n>>m;
for(int i=1;i<=m;++i)
cin>>a[i],++q[a[i]],d=max(d,a[i]),b=max(b,q[a[i]]);
r=b;
while(l<=r)
{
mid=(l+r)/2;
if(check(mid))
l=mid+1,o=mid;
else r=mid-1;
}
cout<<o<<"\n";
return 0;
}
题解 CF1011B Planning The Expedition的更多相关文章
- Planning The Expedition(暴力枚举+map迭代器)
Description Natasha is planning an expedition to Mars for nn people. One of the important tasks is t ...
- B. Planning The Expedition
题目链接:http://codeforces.com/contest/1011/problem/B 题目大意: 输入的n,m代表n个人,m个包裹. 标准就是 每个人一开始只能选定吃哪一个包裹里的食物, ...
- Codeforces div2 #499 B. Planning The Expedition 大水题
已经是水到一定程度了QAQ- Code: #include<cstdio> #include<algorithm> #include<cstring> using ...
- CF B. Planning The Expedition
题意:有n个人和m个食物,给出每一个食物的种类,每个人只会吃一种食物,每个人一天吃一个食物,问这n个人可以撑多少天. 分析:因为题目给出的天数范围比较小所以我们可以从1到100天开始枚举,我们判断如果 ...
- CodeForces - 1015 D.Walking Between Houses
Description Natasha is planning an expedition to Mars for nn people. One of the important tasks is t ...
- Codeforces Round #499 (Div. 2)(1011)
Natasha is planning an expedition to Mars for nn people. One of the important tasks is to provide fo ...
- CodeForces Round #499 Div2
A: Stages 题意: 给你n个字符, 现在需要从中选取m个字符,每个字符的花费为在字母表的第几位,并且如果选了某个字符, 那么下一个选择的字符必须要在字母表的2位之后, 假如选了e 那么 不能选 ...
- CodeForces 1011B
Description Natasha is planning an expedition to Mars for nn people. One of the important tasks is t ...
- poj 2431 Expedition 贪心 优先队列 题解《挑战程序设计竞赛》
地址 http://poj.org/problem?id=2431 题解 朴素想法就是dfs 经过该点的时候决定是否加油 中间加了一点剪枝 如果加油次数已经比已知最少的加油次数要大或者等于了 那么就剪 ...
随机推荐
- DevOps落地实践点滴和踩坑记录-(2) -聊聊平台建设
很久没有写文章记录了,上一篇文章像流水账一样,把所见所闻一个个记录下来.这次专门聊聊DevOps平台的建设吧,有些新的体会和思考,希望给正在做这个事情的同学们一些启发吧. DevOps落地实践点滴和踩 ...
- 汇编/C/C++/MFC/JAVA/C# 进阶群103197177
欢迎广大喜欢编程朋友加入进来.如果是大神请分享你的经验,带领广大小伙伴一起打怪升级得经验:如果是编程新人,那么这里是你不二的选择,分享,奉献是我们追求的目标:我们之中大部分是有一年多工作经验的热血编程 ...
- 线性代数 | Jordan 标准型的笔记
内容概述: 把方阵 A 的特征多项式 \(c(λ)=|λE-A|\) 展开成 \(c(λ)=\sum_ia_i\lambda^i\) 的形式,然后使用神乎其技的证明,得到 \(c(A)=O\),特征多 ...
- 小k工具箱
个人开发软件 大小:21mb左右 基于JavaScript开发 支持系统:安卓/iOS/鸿蒙 未来可期上架各大应用市场 预览图 永久更新维护地址 官方讲解
- python必备基础
1. 基础函数 序号 函数 说明 1 print() 打印 2 input() 输入 3 int() 转化为整形 4 float() 转化为浮点型 5 str() ...
- 使用RandomAccessFile实现数据的插入效果
@Testpublic void test3() { RandomAccessFile raf1 = null; try { raf1 = new RandomAccessFile("hel ...
- C#基础_XML文件读写
使用C#对XML文件进行操作,包括生成一个XML文档,以及读取XML文档中的内容,修改某个元素中的内容 using System; using System.Collections.Generic; ...
- 【java】学习路径23-拆箱与装箱
拿Integer类型和int类型来举例子. 装箱,基本给引用.下面的代码相当于Integer i_test = Integer.valueOf("100"); 注意!过程是自动的. ...
- ak日记 831 dxm
import sys from math import inf line = sys.stdin.readline().strip() vs = list(map(int, line.split()) ...
- docker-compose概述--翻译
Overview of Docker Compose 译文 Docker Compose 是一个用来定义和执行多Docker容器程序的工具,如果使用Compose,你将可以使用一个YAML文件来配置你 ...