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;
    }
    

      

  • 相关阅读:
    c# 操作数据库
    dataview findrows
    C++:gethostname,gethostbyname获取IP地址和计算机名
    MQTT
    STM32操作外部SRAM
    JAVA中最常用的快捷键总结
    Zstack中End Device设备失去父节点时的重新入网处理方法(转)
    VC++ 重叠窗口
    (转载)PLC内部电路常见的几种形式
    VS2005 DoModal函数
  • 原文地址:https://www.cnblogs.com/qingoba/p/13090429.html
Copyright © 2011-2022 走看看