zoukankan      html  css  js  c++  java
  • Week9 作业 C

    题目描述:

    There are n benches in the Berland Central park. It is known that ai people are currently sitting on the i-th bench. Another m people are coming to the park and each of them is going to have a seat on some bench out of n available.

    Let k be the maximum number of people sitting on one bench after additional m people came to the park. Calculate the minimum possible k and the maximum possible k.

    Nobody leaves the taken seat during the whole process.

    思路:

    很简单,求最大值就把所有人放到现在人最多的椅子;求最小值就把人均分到各个椅子

    代码:

    #include <cstdio>
    #include <iostream>
    #include <vector>
    #include <cmath>
    using namespace std;
    vector<int> v; 
    int main()
    {
    	//最大值的最大值就是最多的人加上y
    	//最大值的最小值要看是否会超过y个人来之前的最大值 
    	int mx=-1,mn=INT_MAX;
    	int x,y,t;
    	cin>>x>>y;
    	for(int i=1;i<=x;i++)
    	{
    		scanf("%d",&t);
    		mx=max(t,mx);
    		mn=min(t,mn);
    		v.push_back(t);
    	}
    	//除去坐的最多的座位,能放多少个人不超过mx
    	int Still=0; 
    	for(auto x:v)
    		 Still+=mx-x;
    	if(Still>=y) cout<<mx<<' ';
    	else
    	{
    		//均分 
    		int nowy=y-Still;
    		int More=ceil((double)nowy/(double)x);
    		cout<<mx+More<<' ';
    	}
    	cout<<mx+y<<endl;
    	return 0;
    }
    

      

  • 相关阅读:
    HTML元素 绑定href属性
    form提交不刷新,不跳转页面
    使用MVCPager做AJAX分页所需要注意的地方
    docker基础命令,常用操作
    docker基础
    redis持久化 RDB与AOF
    redis哨兵功能
    redis主从同步
    redis不重启,切换到RDB备份到AOF备份
    redis-cluster(集群)
  • 原文地址:https://www.cnblogs.com/qingoba/p/13090429.html
Copyright © 2011-2022 走看看