微软笔试-Professor Q's Software
来源:互联网 发布:淘宝手机专享价 编辑:程序博客网 时间:2024/06/01 23:35
- 样例输入
33 2123 256123 2 456 256456 3 666 111 256256 1 903 1100100 2 200 200200 1 300200 05 111 2 2 32 2 3 43 2 4 54 2 5 65 2 6 7
- 样例输出
1 1 31 2 21 1 2 3 5
描述
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).
// MS.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include <iostream>#include <stack>#include <vector>#include <map>using namespace std;int main(){int T=0;cin >> T;for (int t = 0; t < T; ++t){int N, M;cin >> N >> M;stack<int> stc;for (int m = 0; m < M; ++m){int tmp;cin >> tmp;stc.push(tmp);}multimap<int, int> s2n;vector<vector<int>> mod(N, vector<int>());vector<int> times(N,0);for (int n = 0; n < N; ++n){int sig;cin >> sig;int num;cin >> num;s2n.insert(pair<int, int>(sig, n));mod[n].resize(num);for (int i = 0; i < num; ++i){cin >> mod[n][i];}}while (!stc.empty()){int stctop = stc.top();stc.pop();auto range = s2n.equal_range(stctop);for (auto p = range.first; p != range.second; ++p){int index = (*p).second;times[index]++;vector<int> sigs = mod[index];for (auto q = sigs.begin(); q != sigs.end(); ++q){stc.push(*q);}}}for (auto iter = times.begin(); iter != times.end(); ++iter){cout << *iter;if ((iter + 1) != times.end())cout << " ";elsecout << endl;}}//system("pause"); return 0;}
- 微软笔试-Professor Q's Software
- 2016微软实习在线笔试题 - Professor Q's Software
- 微软笔试题 HihoCoder#1136: Professor Q's Software 题解
- 微软2016校园招聘在线笔试 - 第二题 Professor Q's Software
- 微软线上笔试-2015-4-3(1,2题) Magic Box && Professor Q's Software
- 题目2 : Professor Q's Software【微软2016校园招聘在线笔试】
- hihoCoder 1136 Professor Q's Software 微软2016校园招聘在线笔试
- 微软2016校园招聘笔试(第一场) Professor Q's Software & Recruitment
- HiHocoder #1136 : Professor Q's Software 微软2016校园招聘在线笔试 【拓扑排序+DP】
- 微软2015实习第二题Professor Q's Software
- Professor Q's Software Java版本
- hihocoder #1136 : Professor Q's Software
- Professor Q's Software---拓扑排序
- hihocoder #1136 : Professor Q's Software 数组解法
- Professor Q's Software——邻接表实现拓扑排序
- A. Professor GukiZ's Robot
- D-Professor GukiZ's Robot
- CF 70D Professor's task题解
- solution Of Pat 1115. Counting Nodes in a BST (30)
- 你不知道的HashMap与HashSet
- 电磁直立车E车模总结报告:
- Problem E
- 【BZOJ4454】C Language Practice
- 微软笔试-Professor Q's Software
- BZOJ_P2440 [中山市选2011]完全平方数(数论+莫比乌斯反演+容斥原理)
- PAT乙级1002
- IntelliJ IDEA 的 Java 热部署插件 JRebel 安装及使用
- eclipse安装gpd插件以及部署jBPM4.4示例
- UVA 1169 【单调队列优化dp】
- Activity的四种启动模式
- 关于搭建环境时的异常The web application [] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to un
- PHP实用方法