题意:有n个人和m个食物,给出每一个食物的种类,每个人只会吃一种食物,每个人一天吃一个食物,问这n个人可以撑多少天。

分析:因为题目给出的天数范围比较小所以我们可以从1到100天开始枚举,我们判断如果是I天了,这些食物够不够N个人吃,够的话继续,不够的话可以跳出循环了,因为这是一种单调关系,如果天数比较大,那可以二分天数;

枚举

#include<stdio.h>
int mp[],a[];
bool book[];
int main( )
{
int n,m,cnt=,x;
scanf("%d%d",&n,&m);
for(int i= ; i<m ; i++)
{
scanf("%d",&x);
mp[x]++;
if(book[x]==)
{
book[x]=;
a[cnt++]=x;
}
} int ans=;
for(int i= ; i<=m ; i++)
{
int num=;
for(int j= ; j<cnt ; j++)
{
num+=(mp[a[j]]/i);
} if(num>=n)
ans=i;
else
break;
}
printf("%d\n",ans);
return ;
}

二分

#include<stdio.h>
int mp[],a[];
bool book[];
int cnt=,n;
bool bl(int mid)
{
int num=;
for(int j= ; j<cnt ; j++)
{
num+=(mp[a[j]]/mid);///每种食物平均I天之和
if(num>=n)
return ;
}
return ; }
int main( )
{
int m,x;
scanf("%d%d",&n,&m);
for(int i= ; i<m ; i++)
{
scanf("%d",&x);
mp[x]++;
if(book[x]==)
{
book[x]=;
a[cnt++]=x;
}
}
int st=,en=0x3f3f3f3f;
int ans=;
while(en-st>)
{
int mid=(st+en)/;
if(bl(mid))
st=mid;
else
en=mid;
} printf("%d\n",(st+en)/);
return ;
}

CF B. Planning The Expedition的更多相关文章

  1. Planning The Expedition(暴力枚举+map迭代器)

    Description Natasha is planning an expedition to Mars for nn people. One of the important tasks is t ...

  2. B. Planning The Expedition

    题目链接:http://codeforces.com/contest/1011/problem/B 题目大意: 输入的n,m代表n个人,m个包裹. 标准就是 每个人一开始只能选定吃哪一个包裹里的食物, ...

  3. Codeforces div2 #499 B. Planning The Expedition 大水题

    已经是水到一定程度了QAQ- Code: #include<cstdio> #include<algorithm> #include<cstring> using ...

  4. 题解 CF1011B Planning The Expedition

    Solution 考虑 二分 . 首先要确定二分的对象,显然二分天数较为简单. 每次找到的 \(mid\) 需要判断是否能让整队人吃饱,那就调用一个 check() . 对于 check() ,求出每 ...

  5. CodeForces - 1015 D.Walking Between Houses

    Description Natasha is planning an expedition to Mars for nn people. One of the important tasks is t ...

  6. CodeForces 1011B

    Description Natasha is planning an expedition to Mars for nn people. One of the important tasks is t ...

  7. 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 ...

  8. CodeForces Round #499 Div2

    A: Stages 题意: 给你n个字符, 现在需要从中选取m个字符,每个字符的花费为在字母表的第几位,并且如果选了某个字符, 那么下一个选择的字符必须要在字母表的2位之后, 假如选了e 那么 不能选 ...

  9. cf 853 A planning [贪心]

    题面: 传送门 思路: 一眼看得,这是贪心[雾] 实际上,我们要求的答案就是sigma(ci*(ti-i))(i=1~n),这其中sigma(ci*i)是确定的 那么我们就要最小化sigma(ci*t ...

随机推荐

  1. 【Docker】docker常用命令

    1.批量删除无tag镜像 docker images|grep none|awk '{print $3}'|xargs docker rmi 2.以特权模式运行容器 docker run --priv ...

  2. 【MySQL】mysql查询强制大小写及替换字段

    强制大小写 select * from test where name like BINARY '%Adc%' mysql替换字段 update test set name= REPLACE (nam ...

  3. vue的proxy和defineProperty区别

    Object.defineProperty(obj,"name",{ set:function(val){ if(var==='lisi'){ console.log(" ...

  4. BZOJ 1006: [HNOI2008]神奇的国度(弦图)

    传送门 解题思路 弦图就是图中任意一个大小\(>=4\)的环至少存在一条两个节点不相邻的边,这样的图称为弦图,弦图有许多优美的性质.一个无向图是弦图当且仅当它有一个完美消除序列,完美消除序列就是 ...

  5. redis配置文件详解-3

    redis3.0以上配置文件 #################################INCLUDES ################################### include ...

  6. Unicode数据类型的是是非非(转)

    转:http://cio.chinabyte.com/344/9002344.shtml 在SQL Server数据库中,数据类型主要分为两类,分别为Unicode数据类型与非Unicode数据类型. ...

  7. 正则匹配class并替换整个class为空

    str.replace(/class=[\"|'](.*?)[\"|'].*?/g, '')

  8. kafka manager遇到的一些问题

    1.启动后第一个报错如下: [error] k.m.a.c.BrokerViewCacheActor - Failed to get broker metrics for BrokerIdentity ...

  9. mac查看python安装路径

    1.terminal : input: which Python 或者 which Python3 2.terminal: input : python  --->import sys  --- ...

  10. 文件上传&&验证文件格式

    $(function(){ $(".layui-progress").hide(); $("[data-upload-file]").each(function ...