题目

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 by student 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?

N个新生入学,每个新生需要到M个office中的某些去办理手续,从一个office到另一个office路上需要花费时间K,第i个新生需要到p[i]个office办理手续(这p[i]个office分别为 o1, w1, o2, w2 ... o(p[i]), w(p[i]) 其中o为office,w为该新生在该office中办理手续需要花费的时间)。 
如果某个office正在办理别的同学的手续,则新到的同学需要在门口等待,如果两个同学同时到达office,则学号低的同学优先。 
    求出这N个同学各自的手续办理完成时间。

输入 
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进入office记为一个事件,且记录student到达office的时间,以及该student在该office中办理手续需要花费的时间。

struct Event{
int student;
int office;
int begin;
int duration;
}

用优先队列维护一个个事件,这样事件就会按照时间排序,同时各个office接待同学是并行的关系,因此需要对每个office都维护该office可以接待新的同学的最早时间。

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string>
#include<iostream>
#include<algorithm>
#include<functional>
#include<queue>
#include<vector>
#include<set>
#include<list>
#include<unordered_map>
#include<unordered_set>
#include<stack>
#include<map>
#include<algorithm>
#include<string.h>
using namespace std;
int N, M, K;
struct Student{
int id;
int arrive_time;
int office_num;
int finish_time;
vector<pair<int, int>> register_offices;
};
Student students[10005];
struct Event{
int student_idx;
int office;
int begin;
int duration;
Event(int s, int o, int b, int d) :student_idx(s), office(o), begin(b), duration(d){};
};
struct Cmp{
bool operator()(const Event& e1, const Event& e2){
if (e1.begin == e2.begin)
return students[e1.student_idx].id > students[e2.student_idx].id;
return e1.begin > e2.begin;
}
};
priority_queue<Event, vector<Event>, Cmp> pq;
int pre[105];
int pos[10005];
void Solve(){
for (int i = 0; i < N; i++){
pq.push(Event(i, students[i].register_offices[0].first, students[i].arrive_time + K, students[i].register_offices[0].second));
pos[i] = 1;
}
memset(pre, -1, sizeof(pre));
while (!pq.empty()){
Event e = pq.top();
pq.pop();
int st = e.student_idx;
if (pre[e.office] > e.begin){
e.begin = pre[e.office];
}
int finish_time = e.begin + e.duration;
if (pos[st] == students[st].office_num){
students[st].finish_time = finish_time;
}
else{
int office = students[st].register_offices[pos[st]].first;
int duration = students[st].register_offices[pos[st]].second;
pq.push({ st, office, finish_time + K, duration });
pos[st] ++;
}
pre[e.office] = finish_time;
}
}
int main(){
scanf("%d %d %d", &N, &M, &K);
int p, o, w;
for (int i = 0; i < N; i++){
scanf("%d %d %d", &students[i].id, &students[i].arrive_time, &p);
students[i].office_num = p;
for (int j = 0; j < p; j++){
scanf("%d %d", &o, &w);
students[i].register_offices.push_back({ o, w });
}
}
Solve();
for (int i = 0; i < N; i++){
printf("%d\n", students[i].finish_time);
}
return 0;
}

微软2017校招笔试题3 registration day的更多相关文章

  1. 微软2017校招笔试题2 composition

    题目 Alice writes an English composition with a length of N characters. However, her teacher requires ...

  2. 微软2014校招笔试题-String reorder

    Time Limit:10000ms Case Time Limit:1000ms Memory Limit:256MB Description For this question, your pro ...

  3. 剑指Offer——腾讯+360+搜狗校招笔试题+知识点总结

    剑指Offer--腾讯+360+搜狗校招笔试题+知识点总结 9.11晚7:00,腾讯笔试.选择题与编程.设计题单独计时. 栈是不是顺序存储的线性结构啊? 首先弄明白两个概念:存储结构和逻辑结构. 数据 ...

  4. 剑指Offer——京东校招笔试题+知识点总结

    剑指Offer--京东校招笔试题+知识点总结 笔试感言 经过一系列的笔试,发觉自己的基础知识还是比较薄弱的,尤其是数据结构和网络,还有操作系统.工作量还是很大的.做到精确制导的好方法就是在网上刷题,包 ...

  5. 剑指Offer——美团内推+校招笔试题+知识点总结

    剑指Offer--美团内推+校招笔试题+知识点总结 前言 美团9.9内推笔试.9.11校招笔试,反正就是各种虐,笔试内容如下: 知识点:图的遍历(DFS.BFS).进程间通信.二叉查找树节点的删除及中 ...

  6. 剑指Offer——CVTE校招笔试题+知识点总结(Java岗)

    剑指Offer(Java岗)--CVTE校招笔试题+知识点总结 2016.9.3 19:00参加CVTE笔试,笔试内容如下: 需要掌握的知识:Linux基本命令.网络协议.数据库.数据结构. 选择题 ...

  7. C# - 2017微软校园招聘笔试题 之 MS Recognition[待解决]

    MS Recognition 在线提交: hihoCoder 1402 http://hihocoder.com/problemset/problem/1402 类似: OpenJudge - I:P ...

  8. hiho #1288 微软2016.4校招笔试题 Font Size

    #1288 : Font Size 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Steven loves reading book on his phone. The ...

  9. 2016京东Android研发校招笔试题

    一.选择题汇总,具体的记不住啦.. 1.计网:ip的网络前缀.SNMP(报文组成):http://blog.csdn.net/shanzhizi/article/details/11606767 参考 ...

随机推荐

  1. 《Linux内核设计与实现》CHAPTER18阅读梳理

    <Linux内核设计与实现>CHAPTER18阅读梳理 [学习时间:2hours] [学习内容:bug的来源分析:bug调试途径] 一.bug来源 1.内核中的bug 内核中的bug表现得 ...

  2. mongodb的使用

    1.启动mongodb 启动mongodb在Linux中可以进入mongodb的bin目录下执行      ./mongod -dbpath=所建立的数据文件夹  -logpath=所建立的日志文件 ...

  3. 利用开源jPlayer播放.flv视频文件

    最近工作中用到视频播放,在网上搜索对比了好几款开源播放插件后,觉得 jPlayer 是比较不错的,故作此记录! 接下来先快速的展示一下 利用jPlayer播放.flv视频的效果: <!DOCTY ...

  4. 会员管理系统全部源代码(C#+EF+SQLite+Winforms实现)

    会员管理系统全部源代码,VS2010开发,使用Ado.net实体框架EF,简化数据库访问层,并能方便的移植到其他数据库.利用数据绑定减少编码量,提高程序的可维护性和可读性.使用Winfoms方便快速界 ...

  5. cocoa pods报错The dependency `Reveal-iOS-SDK` is not used in any concrete target.

    Podfile错误写法,会报错The dependency `Reveal-iOS-SDK` is not used in any concrete target. platform:ios,'7.0 ...

  6. 自动生成pdf书签(仅适用于Adobe Acrobat on windows )

    必备软件 1.Adobe Acrobat. 2.AutoBookmark 为adobe acrobat的自动生成书签的插件(我用的这个:AutoBookmark Standard Plug-in),下 ...

  7. curl常用选项详解

    curl常用选项详解 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 又是下班的时间了,让我们一起来学习一下今天的Linux命令吧~我一半只把自己常用的参数列出来,其他的有但是我们几 ...

  8. IOC 控制反转模式

    1.依赖 依赖就是有联系,有地方使用到它就是有依赖它,一个系统不可能完全避免依赖。如果你的一个类或者模块在项目中没有用到它,恭喜你,可以从项目中剔除它或者排除它了,因为没有一个地方会依赖它。下面看一个 ...

  9. APP-SQLAP-10771:Could not reserve record (匹配PO时候)

    ,) SID, substr(C.SERIAL#,,) SERIAL#, substr(B.,) OBJ_NAME, C.STATUS, C.USERNAME, c.action, C.USER#, ...

  10. Excel应该这么玩——4、命名区域:搞定下拉框

    前三篇都是讲的给Excel元素命名,本篇再介绍一种命名的使用方式:命名区域.区域是多个单元格的集合,可以是单行.单列或者类似表格的单元格矩阵,也可以是不连续的多个单元格,但很少用到.当然,一个单元格也 ...