题意:有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. SCP-bzoj-1090

    项目编号:bzoj-1090 项目等级:Safe 项目描述: 戳这里 特殊收容措施: 区间DP.设计状态f[i][j]表示压缩从第i位到第j位的字符串所需的最小长度.转移方式有三种: •初始化:j-i ...

  2. 回调函数 和 promise对象,及封装API接口

    1.回调函数:https://blog.csdn.net/baidu_32262373/article/details/54969696 注意:回调函数不一定需要用到 return.如果浏览器支持Pr ...

  3. upc组队赛5 Ingenious Lottery Tickets【排序】

    Ingenious Lottery Tickets 题目描述 Your friend Superstitious Stanley is always getting himself into trou ...

  4. web跨域

    之前对于跨域相关的知识一致都很零碎,正好现在的代码中用到了跨域相关的,现在来对这些知识做一个汇总整理,方便自己查看,说不定也可能对你有所帮助. 本篇主要内容如下: 浏览器同源策略 http 请求跨域 ...

  5. 如何深入理解Java泛型

    一.泛型的作用与定义 1.1泛型的作用 使用泛型能写出更加灵活通用的代码泛型的设计主要参照了C++的模板,旨在能让人写出更加通用化,更加灵活的代码.模板/泛型代码,就好像做雕塑时的模板,有了模板,需要 ...

  6. connect failed: 127.0.0.1#953: connection refused

    Problem1 : root@jeremy-VirtualBox:/etc/bind# /etc/init.d/bind9 restart * Stopping domain name servic ...

  7. Neo4j数据库学习一:安装和数据类型常用命令简介

    Neo4j数据库是图数据库 在数据库中,只有节点Nodes和关系Relationships Nodes用圆圈表示,Relationships用有向箭头表示 关系和节点都有属性(键值对) 安装3.3.7 ...

  8. Python运算

    逻辑运算 指数运算 整除 所以,我们来做个运算吧~ 用raw_input()可以从键盘上读取输入,raw_input()中的字符串会在屏幕上面打印出来 用int()转只因为Python默认都是以str ...

  9. spring 注入bean的两种方式

    我们都知道,使用spring框架时,不用再使用new来实例化对象了,直接可以通过spring容器来注入即可. 而注入bean有两种方式: 一种是通过XML来配置的,分别有属性注入.构造函数注入和工厂方 ...

  10. javascript 中的函数

    /*   第二天   */ 函数 函数是js里最有趣的东西了,函数实际上就是对象,每个函数Function类型的实例,函数名实际上是指向函数对象的指针.不带圆括号的函数时访问函数的指针,带圆括号的是调 ...