2017微软秋季校园招聘在线编程笔试(第三题)
来源:互联网 发布:软件项目是 编辑:程序博客网 时间:2024/06/10 03:44
- 样例输入
2 2 100 1600012345 500 2 1 500 2 500 1600054321 1100 1 2 300
- 样例输出
1700 2000
描述
It's H University's Registration Day for new students. There are M offices in H University, numbered from 1 to M. Students need to visit some of them in a certain order to finish their registration procedures. The offices are in different places. So it takes K units of time to move from one office to another.
There is only one teacher in each office. It takes him/her some time to finish one student's procedure. For different students this time may vary. At the same time the teacher can only serve one student so some students may need to wait outside until the teacher is available. Students who arrived at the office earlier will be served earlier. If multiple students arrived at the same time they will be served in ascending order bystudent number.
N new students need to finish his/her registration. They are numbered from 1 to N. The ith student's student number is Si. He will be arrived at H University's gate at time Ti. He needs to visit Pi offices in sequence which are Oi,1, Oi,2, ... Oi,Pi. It takes him Wi,1, Wi,2, ... Wi,Pi units of time to finish the procedure in respective offices. It also takes him K units of time to move from the gate to the first office.
For each student can you tell when his registration will be finished?
输入
The first line contains 3 integers, N, M and K. (1 <= N <= 10000, 1 <= M <= 100, 1 <= K <= 1000)
The following N lines each describe a student.
For each line the first three integers are Si, Ti and Pi. Then following Pi pairs of integers: Oi,1, Wi,1, Oi,2, Wi,2, ... Oi,Pi, Wi,Pi. (1 <= Si <= 2000000000, 1 <= Ti <= 10000, 1 <= Pi <= M, 1 <= Oi,j <= M, 1 <= Wi,j <= 1000)
输出
For each student output the time when he finished the registration.
样例提示
Student 1600012345 will be arrived at the gate at time 500. He needs to first visit Office #1 and then Office #2. He will be arrived at office #1 at time 600. He will leave office #1 at time 1100. Then He will arrive at office #2 at 1200. At the same time another student arrives at the same office too. His student number is smaller so he will be served first. He leaves Office #2 at 1700. End of registration.
Student 1600054321 will be arrived at the gate at time 1100. He will be arrived at Office #2 at 1200. Another student with smaller student number will be served first so he waits for his turn until 1700. He leaves Office #2 at 2000. End of registration.
解题思路:
一个模拟题,用队列模拟一下学生办理手续的先后顺序,再用一个数组记录每个办理手续的地方办理完当前手续的时间即可。
代码:
#include <cstdio>#include <queue>#include <cstring>using namespace std;struct student_info{ int id,s,time,goWhich; bool operator < (const student_info &a) const{ if(time == a.time){ return s > a.s; } return time > a.time; }};struct student{ int s,t,p; int order[105]; int time[105];};int n,m,k;student stu[10005];int ans[10005];int endTime[105];priority_queue<student_info> q;int main(){ int n,m,k; scanf("%d%d%d",&n,&m,&k); for(int i = 0; i < n; i ++){ scanf("%d%d%d",&stu[i].s,&stu[i].t,&stu[i].p); for(int j = 0; j < stu[i].p; j ++){ scanf("%d%d",&stu[i].order[j],&stu[i].time[j]); } q.push((student_info){i,stu[i].s,stu[i].t + k,0}); } /*while(!q.empty()){ student_info now = q.top(); q.pop(); printf("%d %d\n",now.s,now.time); }*/ memset(endTime,0,sizeof(endTime)); while(!q.empty()){ student_info now = q.top(); q.pop(); //printf("%d %d\n",now.s,now.time); if(now.goWhich == stu[now.id].p - 1){ if(endTime[stu[now.id].order[stu[now.id].p-1]] < now.time){ ans[now.id] = now.time + stu[now.id].time[stu[now.id].p-1]; endTime[stu[now.id].order[stu[now.id].p-1]] = now.time + stu[now.id].time[stu[now.id].p-1]; } else{ ans[now.id] = endTime[stu[now.id].order[stu[now.id].p-1]] + stu[now.id].time[stu[now.id].p-1]; endTime[stu[now.id].order[stu[now.id].p-1]] += stu[now.id].time[stu[now.id].p-1]; } } else{ if(endTime[stu[now.id].order[now.goWhich]] < now.time){ endTime[stu[now.id].order[now.goWhich]] = now.time + stu[now.id].time[now.goWhich]; now.time += stu[now.id].time[now.goWhich] + k; } else{ now.time = endTime[stu[now.id].order[now.goWhich]] + stu[now.id].time[now.goWhich] + k; endTime[stu[now.id].order[now.goWhich]] += stu[now.id].time[now.goWhich]; } now.goWhich ++; q.push(now); } } for(int i = 0; i < n; i ++){ printf("%d\n",ans[i]); } return 0;}
- 2017微软秋季校园招聘在线编程笔试(第三题)
- 2017微软秋季校园招聘在线编程笔试(第二题)
- 2017微软秋季校园招聘在线编程笔试
- 2017微软秋季校园招聘在线编程笔试 Composition
- 2017微软秋季校园招聘在线编程笔试
- 2017微软秋季校园招聘在线编程笔试 Composition (DP)
- 2017微软秋季校园招聘在线编程笔试-#1400 : Composition
- 2017微软秋季校园招聘在线编程笔试(第一题)
- 2017微软秋季校园招聘在线编程笔试 题目2 Composition
- 2017微软秋季校园招聘在线编程笔试-#1399 : Shortening Sequence
- 2017微软秋季校园招聘在线编程笔试-#1401 : Registration Day
- 2017微软秋季校园招聘在线编程笔试-#1402 : MS Recognition
- 阿里巴巴2015秋季校园招聘研发工程师在线笔试题
- 微软2014校园招聘笔试编程题
- 2017校园招聘腾讯笔试题 在线编程题
- 微软2016校园招聘4月在线笔试题
- 2017微软校园招聘笔试题
- 阿里巴巴2016年秋季校园招聘C++研发岗在线笔试附加题第一题
- Web:左耳入右耳出(JavaScript>小笔记)
- BMP文件读取
- openfalcon-zookeeper监控 "zkmon"
- 淘宝MM资料Python爬虫1.5
- Hello World
- 2017微软秋季校园招聘在线编程笔试(第三题)
- HTML5 WebSocket 传输消息、图片、音频
- 算法总结(4)--Single Number相关问题
- MFC列表(List Control)中添加项
- leetcode_53 Maximum Subarray_动态规划
- 三扇门理论:无关概率,只关套路
- Android:Touch事件分发机制
- Ubuntu日记——在搭建laravel lnmp环境
- JVM中的直接引用和符号引用