1195: OS job schedulingtime limit: 2 sec memory limit: 128 MB
Submit: 106 solved: 35
[Submit] [Status] [web board] Description
OS (operating system) is to help user solve the problem, such as run job (task ). A Multitasking OS is one that can simultaneously interleave execution of more than one job. it means that, at the same time, more than one job waiting for being processed by the OS. but now that the OS is only one processor, a processor can only execute one job at the same time. so the OS will be decided at a time which one job be processed. each job has three Property: time (the time submit to the system), priority (perform high priority) and length (the running time of job ). in order to improve the throughput (the number of unit time processing jobs) about OS, there are several basic algorithms to solve this problem. they were explained in the following:
FCFS: First come first service
The jobs are executed on first come, first serve basis. It is easy to understand and implement, but it is poor in performance as average wait time is high.
SJF: shortest job first.
It is the best approach to minimize waiting time, but impossible to implement. The processor shocould know in advance how much time process will take.
PBS: Priority Based Scheduling
Each process is assigned a priority. Process with highest priority is to be executed first and so on. Processes with same priority are executed on first come first serve basis.
Today, Chris's teacher gave him a homework: given n jobs and the time of each job submission to the system, use the method of FCFS (the first submit is executed first ), to decide the order of the operation is saved med.
Chris get confused with this problem thoroughly, so he ask you for help. Please help him to solve this problem.
Input
There are multiple input data groups, for each input data group:
The first line of input an integer N (1 ≤ n ≤ 1000), the number of the job shocould to be handled. the next line contains n space-separated integer numbers. the I-th number Ti (1 ≤ I ≤ 1000, 1 ≤ Ti ≤ 1000) denotes the time of I-th job be submitted. it is essential that Ti =tj (1 ≤ I, j ≤ 1000 & I =j)
Output
For each input data group, print n space-separated integer numbers, the I-th number represents the I-th run jobs.
Sample input51 2 3 4 555 4 3 2 153 2 4 1 5 sample output1 2 3 4 4 3 2 14 2 1 3 5 hint
Source
The seventh ACM College Student Program Design Competition of Zhengzhou University
Maybe it was last semester. In that competition, the level was too good. At that time, I didn't dare to do anything in English... Alas :-(
Now, let's look at this question. It's easy !!
AC code:
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;struct fun{int jobi;int t;}job[1010];bool cmp(fun a, fun b){return a.t<b.t;}int main(){int T;while(scanf("%d", &T)!=EOF){int i;for(i=1; i<=T; i++){job[i].jobi=i;scanf("%d", &job[i].t);}sort(job+1, job+T+1, cmp);for(i=1; i<T; i++)printf("%d ", job[i].jobi);printf("%d\n", job[i].jobi);}return 0;}
ZZUOJ-1195-(subject e of the seventh ACM College Student Program Design Competition of Zhengzhou University)