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

      

  • 相关阅读:
    沟通的5个步骤
    安家博客园,发表感想
    postman 简单教程-实现简单的接口测试
    Postman的基本使用
    面试题-如何测试一个APP
    Fiddler快捷方式导出jmeter脚本,傻瓜式
    Servlet学习(三)
    scala学习(一)
    白底抠图
    Servlet学习(二)
  • 原文地址:https://www.cnblogs.com/qingoba/p/13090429.html
Copyright © 2011-2022 走看看