微软2016校园招聘在线笔试-Professor Q's Software
题目2 : Professor Q's Software
描述
Professor Q develops a new software. The software consists of N modules which are numbered from 1 to N. The i-th module will be started up by signal Si. If signal Si is generated multiple times, the i-th module will also be started multiple times. Two different modules may be started up by the same signal. During its lifecircle, the i-th module will generate Ki signals: E1, E2, ..., EKi. These signals may start up other modules and so on. Fortunately the software is so carefully designed that there is no loop in the starting chain of modules, which means eventually all the modules will be stoped. Professor Q generates some initial signals and want to know how many times each module is started.
输入
The first line contains an integer T, the number of test cases. T test cases follows.
For each test case, the first line contains contains two numbers N and M, indicating the number of modules and number of signals that Professor Q generates initially.
The second line contains M integers, indicating the signals that Professor Q generates initially.
Line 3~N + 2, each line describes an module, following the format S, K, E1, E2, ... , EK. S represents the signal that start up this module. K represents the total amount of signals that are generated during the lifecircle of this module. And E1 ... EK are these signals.
For 20% data, all N, M <= 10
For 40% data, all N, M <= 103
For 100% data, all 1 <= T <= 5, N, M <= 105, 0 <= K <= 3, 0 <= S, E <= 105.
Hint: HUGE input in this problem. Fast IO such as scanf and BufferedReader are recommended.
输出
For each test case, output a line with N numbers Ans1, Ans2, ... , AnsN. Ansi is the number of times that the i-th module is started. In case the answers may be too large, output the answers modulo 142857 (the remainder of division by 142857).
- 样例输入
-
3
3 2
123 256
123 2 456 256
456 3 666 111 256
256 1 90
3 1
100
100 2 200 200
200 1 300
200 0
5 1
1
1 2 2 3
2 2 3 4
3 2 4 5
4 2 5 6
5 2 6 7 - 样例输出
-
1 1 3
1 2 2
1 1 2 3 5
直接使用bfs即可:
#include <iostream>
#include <cstdlib>
#include <vector>
#include <unordered_map>
#include <queue> using namespace std; class Module {
public:
int fanin;
int access;
vector<int> fanout;
Module():access(){}
}; int main() { int T, N, M; scanf("%d", &T); for (int i=; i<T; i++) {
scanf("%d%d", &N, &M); // signal slot
unordered_map<int, vector<int> > singal_slot; // module & signal
vector<Module> mods(N);
queue<int> signals; // inital signals
for (int i=; i<M; i++) {
int ts;
scanf("%d", &ts);
signals.push(ts);
} // read module define
for (int i=; i<N; i++) {
int S, K;
scanf("%d%d", &S, &K);
if (singal_slot.count(S) == ) {
// create slot first
singal_slot.insert(make_pair(S, vector<int>()));
} // slot must exist now, register mod
vector<int>& wired_mods = singal_slot[S];
wired_mods.push_back(i); // add fanout signal for current mod
mods[i].fanin = S;
vector<int>& outsig = mods[i].fanout;
for (int i=; i<K; i++) {
int os;
scanf("%d", &os);
outsig.push_back(os);
}
} while (!signals.empty()) {
int sig = signals.front();
signals.pop();
//printf("read signal %d\n", sig);
// retrive the fired mods from signal slot
if (singal_slot.count(sig) == ) {
// no module fired by this signal
continue;
}
vector<int>& ms = singal_slot[sig]; int mlen = ms.size(); for (int i=; i<mlen; i++) {
Module& mod = mods[ms[i]];
// access it
mod.access++;
// fanout signal
vector<int>& outsigs = mod.fanout;
for (int i=; i<outsigs.size(); i++) {
//printf("fanout: %d\n", outsigs[i]);
signals.push(outsigs[i]);
}
}
}
// one iteration over
if (N) {
printf("%d", mods[].access);
}
for (int i=; i<N; i++) {
printf(" %d", mods[i].access);
}
printf("\n");
} //system("pause");
return ;
}
微软2016校园招聘在线笔试-Professor Q's Software的更多相关文章
- 微软2016校园招聘在线笔试 B Professor Q's Software [ 拓扑图dp ]
传送门 题目2 : Professor Q's Software 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Professor Q develops a new s ...
- 微软2016校园招聘在线笔试第二场 题目1 : Lucky Substrings
时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 A string s is LUCKY if and only if the number of different ch ...
- 微软2016校园招聘在线笔试 [Recruitment]
时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 A company plans to recruit some new employees. There are N ca ...
- 题目3 : Spring Outing 微软2016校园招聘在线笔试第二场
题目3 : Spring Outing 时间限制:20000ms 单点时限:1000ms 内存限制:256MB 描述 You class are planning for a spring outin ...
- 微软2016校园招聘在线笔试之Magic Box
题目1 : Magic Box 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 The circus clown Sunny has a magic box. When ...
- hihocoder 1288 : Font Size (微软2016校园招聘4月在线笔试)
hihocoder 1288 笔试第一道..wa了好几次,也是无语..hihocoder错了不会告诉你失败的时候的测试集,这样有时候就很烦.. 遍历所有的字体,从min(w,h)开始逐渐变小开始遍历. ...
- 微软2016校园招聘4月在线笔试 A FontSize
题目链接:http://hihocoder.com/problemset/problem/1288 分析:题目中所求的是最大的FontSize(记为S),其应该满足P*[W/S]*[H/S] > ...
- 微软2016校园招聘4月在线笔试 ABC
题目链接:http://hihocoder.com/contest/mstest2016april1/problems 第一题:输入N,P,W,H,代表有N段文字,每段有ai个字,每行有⌊W/S⌋个字 ...
- 微软2016校园招聘4月在线笔试 hihocoder 1289 403 Forbidden
时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描写叙述 Little Hi runs a web server. Sometimes he has to deny acces ...
随机推荐
- placeholder插件详解
placeholder插件是用来实现input或者textarea文本框显示默认文字的功能,当获得焦点时,默认文字消失.用户按删除键,把输入的字符删除掉,并失去焦点时,默认文字又出现等功能.使用此插件 ...
- cnpm安装过程中提示optional install error: Package require os(darwin) not compatible with your platform(win32)解决方法
运行cnpm install后,出现 虽然提示不适合Windows,但是问题好像是sass loader出问题的.所以只要执行下面命令即可: 方案一: cnpm rebuild node-sass # ...
- 如何无人值守安装linux系统(上)
如何开始 Linux 的无人值守安装 一.预备知识: I.什么是PXE PXE并不是一种安装方式,而是一种引导方式.进行PXE安装的必要条件是要安装的计算机中包含一个PXE支持的网卡(NIC),即网卡 ...
- mxonline实战4,用户登陆页面2和用户注册1
一. 基于类来定义view.py diango中使用基于类来定义views的功能,其实更加方便,因为这样可继承一些定义好的基类,来减少我们的代码量 1. 使用基于类的方法,来重新定 ...
- Python标准库中的生成器函数
一.用于过滤的生成器函数 - 从输入的可迭代对象中产出元素的子集,而不修改元素本身 import itertools l1 = [1,2,3,4,5] l2 = [True,False,True,Fa ...
- js中数组的操作方法
今天给大家带来一篇有关数组操作方法的文章. 新建数组 方法一:通过new运算符创建一个数组构造函数. var arr = new Array(); 方法二:通过方括号直接创建直接量数组. var ar ...
- hiho#1457 重复旋律7 求子串和 后缀自动机
题目传送门 题意: 给出若干个串,求所有子串的和,子串和的定义为十进制数,取模1e9+7. 思路: 对于一个串来说,一个状态p就代表着$right$相同的集合,假设我们已经知道了状态p的$sum$,以 ...
- How to install Jenkins on CentOS 7
How to install Jenkins on CentOS 7 on March 3, 2018 by AmirLeave a comment Introduction Jenkins is a ...
- Ejb3.0+jboss 8 创建EJB demo
工具:Eclipse , wildfly 8.x 1.服务端: 1)创建接口 package com.welv.ejb; public interface FirstEjb { public Stri ...
- HTML5 表单 中
input 属性 autofocus 页面加载时自动获得焦点 required 非空字段输入框 placeholder 提供一种提示(hint),输入域为空时显示. pattern 规定验证inp ...