CF B. Planning The Expedition
题意:有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的更多相关文章
- 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 ...
- 题解 CF1011B Planning The Expedition
Solution 考虑 二分 . 首先要确定二分的对象,显然二分天数较为简单. 每次找到的 \(mid\) 需要判断是否能让整队人吃饱,那就调用一个 check() . 对于 check() ,求出每 ...
- 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 1011B
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 那么 不能选 ...
- cf 853 A planning [贪心]
题面: 传送门 思路: 一眼看得,这是贪心[雾] 实际上,我们要求的答案就是sigma(ci*(ti-i))(i=1~n),这其中sigma(ci*i)是确定的 那么我们就要最小化sigma(ci*t ...
随机推荐
- Wireshark协议分析1
一.界面简介 1.抓包工具栏 2.文件工具栏 3.包定位工具栏 4.颜色以及滚动界面工具栏 5.数据包列表字体定义工具栏 6.首选项工具栏 二.过滤规则 1.过滤 IP ip.src eq 192 ...
- [CSP-S模拟测试47]反思+题解
打开题面,T3似乎被换过了.(那我就更有理由直接弃掉了) T1是我最害怕的乱搞题,赶紧扔了看T2.发现是个sb板子?雨天的尾巴弱化版? 然而线段树合并早忘干净了(最近几道可以线段树合并的题都是用别的方 ...
- 【Spring Boot】Spring Boot项目部署到外部Tomcat容器
一.修改项目打包方式为war包 修改pom.xml文件中packaging属性项 <packaging>war</packaging> 修改pom.xml文件增加一个依赖 &l ...
- git rollback
http://stackoverflow.com/questions/1616957/how-do-you-roll-back-reset-a-git-repository-to-a-particul ...
- STL中六大组件
1)容器(Container),是一种数据结构,如list,vector,和deques ,以模板类的方法提供.为了访问容器中的数据,可以使用由容器类输出的迭代器: 容器(container)用于存放 ...
- c# 关于DataTable
1.DataRow数组 转DataTable using (SqlConnection con = new SqlConnection("server=.;uid=sa;pwd=123;da ...
- NOIp2018 爆零记
几个月没动博客了,原以为NOIp之后能有个喜报让我重新更博的 我就讲讲自己的爆零经历吧 Day 0: 洛谷签到第99天,明天签到第100天, 吉利得很(flag已立) 去年第一次参加NOIp,那次Da ...
- python获取每日涨跌停股票统计,封闭时间和打开次数
接口:limit_list 描述:获取每日涨跌停股票统计,包括封闭时间和打开次数等数据,帮助用户快速定位近期强(弱)势股,以及研究超短线策略. 限量:单次最大1000,总量不限制 积分:用户积2000 ...
- Java面试宝典(1)Java基础部分
Java面试宝典 题目,日积月累,等到出去面试时,一切都水到渠成,面试时就自然会游刃有余了. 答题时,先答是什么,再答有什么作用和要注意什么(这部分最重要,展现自己的心得) 答案的段落分别,层次分明, ...
- 人生苦短,我学PYTHON
人生苦短我学PYTHON 坚持 努力