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 ...
随机推荐
- 绝不划水队Alpha冲刺阶段博客目录
绝不划水队Alpha冲刺阶段博客目录 一.Scrum Meeting 第六周会议记录 第七周会议记录 二.测试报告 alpha阶段测试报告 三.习得的软工原理/方法/技能? 李浩杰: (1)一开始分工 ...
- 【已转移】【Java架构:基础技术】一篇文章搞掂:Spring
本文篇幅较长,建议合理利用右上角目录进行查看(如果没有目录请刷新). 本文是对<SPRING实战第4版>的总结,大家也可以去仔细研读该书 [------------------------ ...
- float不完整带来的IE7下的不兼容
这种原因是因为搜索用了float:right;添加报考院校和导入文件没有用float; 解决的方法是:1.给添加报考院校和导入文件分别添加float:left;2.把搜索那部分代码写在添加报考院校和导 ...
- centos安装virtualbox
参考:http://www.if-not-true-then-false.com/2010/install-virtualbox-with-yum-on-fedora-centos-red-hat-r ...
- myCat读写分离+传统主从
1 Mycat介绍: mycat是最近很火的一款国人发明的分布式数据库中间件,它是基于阿里的cobar的基础上进行开发的 准备环境: db01主 10.0.0.51 db02备 10.0.0. ...
- activiti7启动流程实例,动态设置assignee人
package com.zcc.activiti03; import org.activiti.engine.ProcessEngine;import org.activiti.engine.Proc ...
- 在响应式布局中,碰到图片不会自动缩放,因此需要一段js脚本
<script> (function (doc, win) { var docEl = doc.documentElement, resizeEvt = 'orientationchang ...
- 廖雪峰的git学习笔记
安装完后,每个机器都要自报家门 Config--配置 global--全局参数 配置全局用户名 $git config --global user.name “Your Name” 配置邮箱 ...
- LeetCode Array Easy169. Majority Element
Description Given an array of size n, find the majority element. The majority element is the element ...
- Java删除过期文件
public static void main(String[] args) throws IOException { long cut = LocalDateTime.now().minusWeek ...