zoukankan      html  css  js  c++  java
  • CF1011B

    题目链接

    题目描述

    有N个人M份食物,每人每天吃一份食物,每份食物有一个种类ai,一个人从开始到结束只能吃一种类型的食物,问最多能坚持几天.

    输入输出格式

    输入格式:

    第一行n,m
    第二行m个数,表示每份食物的种类

    输出格式:

    一个整数,表示最大能坚持的天数.

    样例

    输入样例 输出样例
    4 10 2
    1 5 2 1 1 1 2 5 7 2
    100 1 0
    1

    思路

    1.二分

    统计每种类型食物份数
    然后从大到小排序
    二分最大天数
    枚举统计是否成立

    #include <algorithm>
    #include <iostream>
    #include <cstring>
    #include <cstdio>
    #include <cmath>
    #include <queue>
    #include <stack>
    #include <list>
    #include <set>
    #include <map>
    #define ll long long
    #define ull unsigned long long
    #define ci const int&
    #define cl const long long&
    #define cul const undigned long long&
    #define io_f std::ios::sync_with_stdio(false)
    using namespace std;
    
    int n,m;
    int arr[101];
    
    inline bool cmp(ci x,ci y) {
    	return x>y;
    }
    
    inline bool check(ci x) {
    	int tmp=n;
    	for(int i=1;i<=m&&tmp>0;i++) {
    		tmp-=arr[i]/x;
    	}
    	if(tmp<=0)return 1;
    	return 0;
    }
    
    int main() {
    	io_f;
    	int a;
    	cin>>n>>m;
    	for(int i=1;i<=m;i++) {
    		cin>>a;
    		arr[a]++;
    	}
    	sort(arr+1,arr+100+1,cmp);
    	int l=0,r=200;
    	while(l+1<r) {
    		int mid=(l+r)>>1;
    		if(check(mid))l=mid;
    		else r=mid;
    	}
    	cout<<l;
    
    	return 0;
    }
    
  • 相关阅读:
    面向对象的相关知识
    模块的导入
    正怎表达式在爬虫里的应用
    前端~css
    CSS知识点
    初识Html
    Python之路--协程/IO多路复用
    进程
    锁 和 线程池
    操作系统-并发-线程-进程
  • 原文地址:https://www.cnblogs.com/ullio/p/9383824.html
Copyright © 2011-2022 走看看