• 欢迎访问废江's博客 QQ群
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏本站吧

Queue(任务题目)

AOJ 站点默认 1年前 (2020-04-05) 486次浏览 已收录 52个评论
文章目录[隐藏]

Question

Time Limit : 1 sec , Memory Limit : 131072 KB , isSolved :
There are n processes in a queue. Each process has namei and timei. The round-robin scheduling handles the processes in order. A round-robin scheduler gives each process a quantum (a time slot) and interrupts the process if it is not completed by then. The process is resumed and moved to the end of the queue, then the scheduler handles the next process in the queue.

For example, we have the following queue with the quantum of 100ms.

A(150) – B(80) – C(200) – D(200)
First, process A is handled for 100ms, then the process is moved to the end of the queue with the remaining time (50ms).

B(80) – C(200) – D(200) – A(50)
Next, process B is handled for 80ms. The process is completed with the time stamp of 180ms and removed from the queue.

C(200) – D(200) – A(50)
Your task is to write a program which simulates the round-robin scheduling.
Input
n q
name1 time1
name2 time2

namen timen
In the first line the number of processes n and the quantum q are given separated by a single space.

In the following n lines, names and times for the n processes are given. namei and timei are separated by a single space.

Output
For each process, prints its name and the time the process finished in order.

Constraints
1 ≤ n ≤ 100000
1 ≤ q ≤ 1000
1 ≤ timei ≤ 50000
1 ≤ length of namei ≤ 10
1 ≤ Sum of timei ≤ 1000000
Sample Input 1
5 100
p1 150
p2 80
p3 200
p4 350
p5 20
Sample Output 1
p2 180
p5 400
p1 450
p3 550
p4 800

Meaning

n是任务总个数,q是cpu完成某个任务不能超过的时间。给定一串任务,但是时间q长的任务不能一次完成,需要先存起来,进行后面的任务,等到一遍过后再回头完成之前的任务。用队列就ok了

Solution

这里我用的是我之前数据结构课自己写的队列代码

Coding

Summary

循环队列的关键实现:front=(front+1)%max rear=(rear+1)%max
队列中用elemtype来声明数据的好处是可以随题意改变来存储任何想要的数据形式
头文件:#include//malloc和free头文件,本地不加可以跑,但是一些oj不行

个人博客 , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:Queue(任务题目)
喜欢 (0)
[]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到
(52)个小伙伴在吐槽
  1. http://clomidst.com/# clomid generic name
    匿名2021-04-13 22:07 (11小时前)回复 Windows 10 | Chrome 83.0.4086.0
  2. Hey there! I just wanted to ask if you ever have any trouble with hackers? My last blog (wordpress) was hacked and I ended up losing months of hard work due to no backup. Do you have any solutions to protect against hackers?
    匿名2021-04-13 11:48 (22小时前)回复 Windows 10 | Chrome 62.0.3202.94
  3. dating sites for over 50 chat free dating site
    匿名2021-04-12 10:46 (2天前)回复 Windows 8.1 | Chrome 83.0.4103.61
  4. viagra 100mg viagra without a doctor prescription viagra without a doctor prescription canada
    匿名2021-04-12 07:01 (2天前)回复 Windows 10 | Chrome 83.0.4086.0
  5. free adult dating sites personal ads free
    匿名2021-04-11 20:08 (3天前)回复 Windows 7 | Chrome 83.0.4103.61
  6. viagra cheap buy viagra online without prescription buying viagra online without prescription
    匿名2021-04-11 11:15 (3天前)回复 Windows 10 | Chrome 83.0.4103.34
  7. when will viagra be generic viagra without prescription buy viagra online without prescription
    匿名2021-04-11 04:03 (3天前)回复 Windows 10 | Chrome 83.0.4089.0
  8. when will viagra be generic viagra no prescription viagra online no prescription
    匿名2021-04-10 14:37 (4天前)回复 Windows 7 | Chrome 83.0.4103.61
  9. cialis pills online: cialis pills levitra pills
    匿名2021-04-10 02:27 (4天前)回复 Windows 10 | Chrome 83.0.4103.0
  10. dating sites for over 50 dating personal ads
    匿名2021-04-09 12:48 (5天前)回复 Windows 10 | Chrome 83.0.4103.0
  11. mail order erectile dysfunction pills: levitra pills best male erectile dysfunction pill
    匿名2021-04-08 18:23 (6天前)回复 Windows 8.1 | Chrome 83.0.4103.61
  12. mail order erectile dysfunction pills: best erectile dysfunction pills review cialis ed pills
    匿名2021-04-07 17:17 (7天前)回复 Windows 7 | Chrome 83.0.4093.3
  13. india pharmacy without dr prescriptions: united pharmacy india indian online pharmacies review
    匿名2021-04-07 08:00 (1周前)回复 Windows 7 | Chrome 83.0.4103.24
  14. buy medication online from india: online medications from india order medications online from india
    匿名2021-04-06 22:17 回复 Windows 10 | Chrome 83.0.4103.14
  15. order medications online from india: best india pharmacy prescriptions from india
    匿名2021-04-05 18:47 回复 Windows 10 | Chrome 83.0.4103.34
  16. meds from india: order prescription drugs from india india pharmacy mail order
    匿名2021-04-05 03:51 回复 Windows 8.1 | Chrome 83.0.4103.61
  17. buy suprax: augmentin generic fucidin tablets
    匿名2021-04-03 18:07 回复 Windows 10 | Chrome 83.0.4096.0
  18. zyvox tablets: chloramphenicol online order cephalexin
    匿名2021-04-03 03:40 回复 Windows 10 | Chrome 83.0.4099.2
  19. buy clindamycin: buy tetracycline generic floxin price
    匿名2021-04-02 15:45 回复 Windows 8.1 | Chrome 83.0.4103.44
  20. cefadroxil generic: clindamycin tablets clindamycin capsules
    匿名2021-04-02 02:27 回复 Windows 10 | Chrome 83.0.4086.0
  21. http://zithromaxproff.com/# can i buy zithromax over the counter in canada buy zithromax 500mg online
    匿名2021-03-31 20:56 回复 Windows 8.1 | Chrome 83.0.4103.61
  22. https://zithromaxproff.com/# zithromax capsules zithromax tablets for sale
    匿名2021-03-31 05:03 回复 Windows 10 | Chrome 83.0.4103.44
  23. https://zithromaxproff.com/# generic zithromax azithromycin buy zithromax online with mastercard
    匿名2021-03-30 18:27 回复 Windows 7 | Chrome 83.0.4093.3
  24. http://zithromaxproff.com/# where can i buy zithromax medicine zithromax cost australia
    匿名2021-03-30 03:38 回复 Windows 10 | Chrome 83.0.4096.0
  25. prednisone cream: cheap prednisone - prednisone 5084
    匿名2021-03-28 22:45 回复 Windows 10 | Chrome 83.0.4103.34
  26. zithromax canadian pharmacy: zithromax for sale - zithromax z-pak
    匿名2021-03-28 01:03 回复 Windows 10 | Chrome 83.0.4103.24
  27. http://hydroxychloroquinest.com/# hydroxychloroquine 90 mg
    匿名2021-03-26 11:14 回复 Windows 10 | Chrome 83.0.4093.3
  28. order prednisone on line: cheap prednisone - prednisone 2.5 tablet
    匿名2021-03-25 23:29 回复 Windows 10 | Chrome 83.0.4103.61
  29. cheap ed pills from canada buy ed pills from canada male enhancement pills
    匿名2021-03-24 08:23 回复 Windows 7 | Chrome 83.0.4102.0
  30. cheap ed pills from india ed pills without a doctor prescription erection pills
    匿名2021-03-22 15:02 回复 Windows 10 | Chrome 83.0.4103.0
  31. viagra from india https://viagrapills100.com/ viagra from canada
    匿名2021-03-21 05:27 回复 Windows 10 | Chrome 83.0.4103.34
  32. cheap viagra online https://viagrapills100.com/ viagra 100mg price
    匿名2021-03-20 18:51 回复 Windows 10 | Chrome 83.0.4103.34
  33. viagra 100mg price https://viagrapills100.com/ viagra amazon
    匿名2021-03-20 04:35 回复 Windows 7 | Chrome 83.0.4103.61
  34. buy viagra online canada https://viagrapills100.com/ generic viagra walmart
    匿名2021-03-19 17:48 回复 Windows 10 | Chrome 83.0.4103.61
  35. buy real viagra online https://viagrapills100.com/ viagra without a doctor prescription
    匿名2021-03-19 05:36 回复 Windows 7 | Chrome 83.0.4103.61
  36. over the counter viagra https://viagrapills100.com/ buy real viagra online
    匿名2021-03-18 18:11 回复 Windows 10 | Chrome 83.0.4103.61
  37. I love studying and I conceive this website got some genuinely useful stuff on it! .
    匿名2021-03-18 06:20 回复 Windows 10 | Chrome 62.0.3202.94
  38. where can i buy valtrex over the counter valtrex discount
    匿名2021-03-18 02:29 回复 Windows 10 | Chrome 83.0.4103.44
  39. aralen chloroquine tablet price cure for ed
    匿名2021-03-17 17:00 回复 Windows 10 | Chrome 83.0.4103.14
  40. cost of viagra buy generic 100mg viagra online where to buy viagra online
    匿名2021-03-15 19:58 回复 Windows 10 | Chrome 83.0.4103.44
  41. order viagra online viagra amazon order viagra online
    匿名2021-03-14 20:57 回复 Windows 10 | Chrome 83.0.4093.3
  42. viagra online usa viagra over the counter walmart when will viagra be generic
    匿名2021-03-14 13:19 回复 Windows 10 | Chrome 83.0.4099.2
  43. best place to buy viagra online viagra over the counter walmart viagra cost per pill
    匿名2021-03-13 23:10 回复 Windows 10 | Chrome 83.0.4098.0
  44. where can i buy viagra over the counter viagra over the counter walmart viagra cost per pill
    匿名2021-03-13 00:40 回复 Windows 10 | Chrome 83.0.4103.34
  45. order viagra online viagra without a doctor prescription usa when will viagra be generic
    匿名2021-03-12 02:25 回复 Windows 10 | Chrome 83.0.4093.3
  46. where to buy viagra online 100mg viagra where to buy viagra online
    匿名2021-03-11 18:19 回复 Windows 10 | Chrome 83.0.4103.34
  47. buy prescription drugs trusted india online pharmacies
    匿名2021-03-11 00:09 回复 Windows 8.1 | Chrome 83.0.4103.61
  48. india pharmacy buy cheap prescription drugs online
    匿名2021-03-09 18:00 回复 Windows 10 | Chrome 83.0.4103.24
  49. generic pills for sale overseas pharmacies shipping to usa
    匿名2021-03-09 02:19 回复 Windows 10 | Chrome 83.0.4086.0
  50. buy prescription drugs generic drugs without doctor's prescription
    匿名2021-03-08 17:20 回复 Windows 7 | Chrome 83.0.4103.24
  51. tadalafil 30 mg: http://tadalafilonline20.com/ tadalafil
    匿名2021-03-06 04:27 回复 Windows 7 | Chrome 83.0.4102.0
  52. tadalafil tablets generic tadalafil united states tadalafil
    匿名2021-03-05 19:36 回复 Windows 10 | Chrome 83.0.4098.0