题意:有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. 「NOI2017」蚯蚓排队 解题报告

    「NOI2017」蚯蚓排队 这题真的草 你考虑\(k\)这么小,每次合并两个串,增加的有用串的数量是\(O(k^2)\)的,暴力加入这些串,求一下这些串的Hash值,塞到Hash表里面去 这里采用类似 ...

  2. 使用Intent实现Activity之间传值与跳转(转)

    转:http://blog.csdn.net/cjjky/article/details/6337447 在一个Android的应用程序中,很少只存在一个Activity,一般都有多个Activity ...

  3. 个人笔记 - C++相关收藏

    一.文件操作 1.C++从txt文件中读取二维的数组

  4. Tomcat_shutdown

    @echo off echo 执行开始时间 date/t time/t echo *********************************************** echo 正在关闭To ...

  5. Eclipse转idea改设置

    1 自动导包:画圈的打钩,实现自动导包,去除无用包.导入的类名相同时需要自己手动导包->  alt+enter. 2:修改快捷键 左移光标,右移同理. 上移光标:下移同理 光标移至行首,行末为e ...

  6. upc组队赛6 Canonical Coin Systems【完全背包+贪心】

    Canonical Coin Systems 题目描述 A coin system S is a finite (nonempty) set of distinct positive integers ...

  7. Rust <10>:宏导出、导入

    源 crate 中使用 #[macro_export] 属性标记的宏,调用者可在导入此 crate 时添加 #[macro_use] 属性使用. 没有 #[macro_export] 的宏,外部不可见 ...

  8. python学习笔记:模块——time模块

    timetime模块提供各种时间相关的功能,与时间相关的模块有:time,datetime,calendar等. 时间有三种表示方式,一种是时间戳.一种是格式化时间.一种是时间元组.时间戳和格式化时间 ...

  9. js实现页面跳转的几种方法小结

    地址:https://www.jb51.net/article/84335.htm 地址:https://blog.csdn.net/tsoteo/article/details/77849403

  10. 为什么javaBean要有get/set方法的设计

    可以应对将来的修改,比如有一个以长度计算的项目开发好了,过段时间客户说这个项目要在美国上市,有了javaBean只要把所有以厘米计算的单位都乘以2.54转化为正确单位交给客户 public class ...