NYOJ 179 LK's problem (排序模拟)

链接:click here~~

题意:

描述

LK has a question.Coule you help her?

It is the beginning of the day at a bank, and a crowd  of clients is already waiting for the entrance door to  open.

Once the bank opens, no more clients arrive, and  tellerCount tellers begin serving the clients. A

teller takes serviceTime minutes to serve each client.  clientArrivals specifies how long each client has  already been waiting at the moment when the bank door  opens. Your program should determine the best way to arrange the clients into tellerCount
queues, so that  the waiting time of the client who waits longest is minimized. The waiting time of a client is the sum of  the time the client waited outside before the bank opened, the time the client waited in a queue once the  bank opened until the service
began, and the service time of the client. Return the minimum waiting time for the client who waits the longest.

输入
The input will consist of several test cases. For each test case, one integer N (1<= N <= 100) is given in the first line. Second line contains N integers telling us the time each client had waited.Third
line contains tow integers , teller‘s count and service time per client need. The input is terminated by a single line with N = 0.
输出
For each test of the input, print the answer.
样例输入
2
1 2
1 10
1
10
50 50
0

样例输出

21
60

题意银行开门之前,一些人已经在门口等着办理业务。一个人等待的时间=开门前等待时间+开门后排队时间+办理业务所用时间。每个人办理业务所用时间相同,且看门后没有新增的人。问如何安排这些人的次序,能够使得等待时间最长的那个人等待的时间最短。求等待时间最长的那个人等待的时间的最小值。

每组数据先输入一个N,代表有N个人,第二行有N个数,代表每个人在银行开门前的等待时间,第三行有二个数,分别代表银行服务人员的个数和每个人办理业务所用的时间(每个人所用时间相同).输出等待时间最长的那个人等待的时间的最小值。

思路:先对开门前等待时间排序后,求出每一个人所用的时间(开门前等待时间长的先办理)然后再对每个人所用时间排序,输出最大的那个时间

代码:

/*
先对开门前等待时间排序后,求出每一个人所用的时间(开门前等待时间长的先办理)
然后再对每个人所用时间排序,输出最大的那个时间
*/
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
using namespace std;
#define Max(a,b) {a>b?a:b}
int Time[110],dp[110];
int main()
{
    int n,m,i,j,a,b;
    while(cin>>n && n!=0)
    {
        for(i=0; i<n; i++)
            cin>>Time[i];
        cin>>a>>b;
        sort(Time,Time+n);
        for(j=0,i=n-1; i>=0; i=i-a,j++)
            dp[j]=Time[i]+b*(j+1);
        sort(dp,dp+j);
        cout<<dp[j-1]<<endl;
    }
    return 0;
}

When you want to give up, think of why you persist until now !

NYOJ 179 LK's problem (排序模拟)

时间: 2024-12-25 11:53:07

NYOJ 179 LK's problem (排序模拟)的相关文章

NYOJ 280 LK的项链 &amp;&amp;POJ 2409 Let it Bead(polya 定理)

NYOJ 280 LK的项链  :click here POJ 2409 Let it Bead:click here 题意:一盒有红.蓝.绿三种颜色的珠子,每种颜色珠子的个数都大于24,现在LK想用这一盒珠子穿出一条项链,项链上的珠子个数为n(0<=n<=24),请你帮她计算一下一共可以用这一盒珠子可以穿出多少条不同的项链.通过旋转.翻转达到同一种状态的被认为是相同的项链. poj 上是c种颜色,s个珠子组成,数据比24小. 思路:今天刚接触到polya 定理: Polya定理:设G是n个对

HDU 1022 Train Problem I 模拟栈题解

火车进站,模拟一个栈的操作,额外的栈操作,查看是否能按照规定顺序出栈. 数据量很少,故此题目很容易AC. 直接使用数组模拟就好. #include <stdio.h> const int MAX_N = 10; char inOrder[MAX_N], outOrder[MAX_N], stk[MAX_N]; bool rs[MAX_N<<2]; int n; int main() { while (scanf("%d", &n) != EOF) { s

acm集训训练赛B题【排序+模拟】

一.原题 Description Being a programmer, you like arrays a lot. For your birthday, your friends have given you an array a consisting of ndistinct integers. Unfortunately, the size of a is too small. You want a bigger array! Your friends agree to give you

zoj3780 Paint the Grid Again 拓扑排序模拟

比赛时候看完题目就觉得是拓扑排序,当时心里隐隐觉得跟相框叠加那个题有点相似的 然后wzy问我no solution 是什么情况,我就一直去想是不是构成了什么排列就一定是no solution 其实只用再参考相框叠加那个题往前想一丁点就够了,就是从最后涂的那一层开始往前找,每一次都必然有一行或一整列是一样的 每次按逆字母序删除这一行或列就是了. 拓扑排序的题总是类似而且简单的,找到关系,敲代码完全不存在问题. #include <iostream> #include <cstring>

Milking Cows 挤牛奶 USACO 排序 模拟

1005: 1.2.1 Milking Cows 挤牛奶 时间限制: 1 Sec  内存限制: 128 MB提交: 15  解决: 9[提交] [状态] [讨论版] [命题人:外部导入] 题目描述 1.2.1 Milking Cows 挤牛奶 (milk2.pas/c/cpp) 三个农民每天清晨5点起床,然后去牛棚给3头牛挤奶.第一个农民在300秒(从5点开始计时)给他的牛挤奶,一直到1000秒.第二个农民在700秒开始,在 1200秒结束.第三个农民在1500秒开始2100秒结束.期间最长的至

NYOJ 707 A Simple Problem(结构体排序) 睡前一水~~

链接:click here 题意: A Simple Problem 时间限制:3000 ms  |  内存限制:65535 KB 难度:2 描述 You know, just as the title imply, this is a simple problem. In a contest, given the team-id, solved, penalty of all the teams, tell me the champion.If the numbers of solved pr

HDU 5924 Mr. Frog’s Problem 【模拟】 (2016CCPC东北地区大学生程序设计竞赛)

Mr. Frog's Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 312    Accepted Submission(s): 219 Problem Description One day, you, a clever boy, feel bored in your math class, and then fall

NYOJ 2356 哈希计划(模拟)

题目链接: http://acm.nyist.me/JudgeOnline/problem.php?id=2356 题目描述 众所周知,LLM的算法之所以菜,就是因为成天打游戏,最近LLM突然想玩<金庸群侠传X>,结果进去后各种被虐,LLM就开始研究这个游戏的代码,顺便还学会了一点点点点lua语言,然后就开始了伟大的改游戏代码之旅,然后LLM发现自己too young了,这个游戏把所有的文本都进行了哈希,如果自己改了代码或者剧情文本的话它哈希出来的值就会和原来的哈希值不一样......然后游戏

leetCode 179. Largest Number 字符串排序 | Medium

179. Largest Number Given a list of non negative integers, arrange them such that they form the largest number. For example, given [3, 30, 34, 5, 9], the largest formed number is 9534330. Note: The result may be very large, so you need to return a st