Boss
2016-07-08 17:36
225 查看
Boss
题意:n个人,m个从属关系,i次操作,T开头代表把两人职位对调,P要求搜索对应人的上司中职位最年轻的
解法:应用指针对调,搜索时直接dfs
#include <iostream> #include <cstring> #include <stdio.h> #include <stdlib.h> using namespace std; int age[600], last[600], point[600], n, m, q, x, y, ans; int a[70000], nnext[70000], tot, d[600]; bool flag[600]; void insert(int x, int y) { tot++; a[tot] = y; nnext[tot] = last[x]; last[x] = tot; } int main() { while (scanf("%d %d %d", &n, &m, &q) != EOF) { memset(last, 0, sizeof(last)); for (int i = 1; i <= n; i++) { cin >> age[i]; point[i] = i; } tot = 0; for (int i = 1; i <= m; i++) { cin >> x >> y; insert(y, x); } char c; for (int qq = 1; qq <= q; qq++) { cin >> c; if (c == 'P') { memset(flag, 1, sizeof(flag)); cin >> x; d[0] = 1; d[1] = point[x]; ans = -1; int i = 0, j = 1; while (i < j) { i++; int k = last[d[i]]; while (k != 0) { if (flag[a[k]]) { flag[a[k]] = false; d[++j] = a[k]; } k = nnext[k]; } } for (int i = 1; i <= n; i++) if (!flag[point[i]]) { if (age[i] < ans || ans == -1) ans = age[i]; } if (ans == -1) cout << "*" << endl; else cout << ans << endl; } else { cin >> x >> y; int temp = point[x]; point[x] = point[y]; point[y] = temp; } } } }
相关文章推荐
- Swift3.0语法--字符串和字符
- Redis数据库实现
- 实现切换效果的样式
- 自制的超好用jQ插件,弹层,模态窗口插件
- 第一次的博客
- Python常用内建模块——学习笔记
- mysql replication principle--转
- 配置云服务器 FTP 服务
- 位运算
- 全选取消全选网上没看到自己喜欢的。
- pta-寻找大富翁
- 15. ubuntu 16.04 LTS 安装FastFDS 5.05
- Mysql 对比两张表数据
- Android静态安全检测 -> Content Provider组件暴露
- 零起点学C++ 第四章 C++数据结构
- spark性能调优:资源优化
- 自定义popwindow的spinner下拉列表
- Android开发艺术探索 第4章
- Unable to load configuration. - action 解决方案(struts 2 使用笔记)
- opencv-视频处理-实时的前景检测-Vibe算法