HDU 3974 Assign the task [并查集扩展]
来源:互联网 发布:js获取被选中的radio 编辑:程序博客网 时间:2024/05/16 14:38
http://acm.hdu.edu.cn/showproblem.php?pid=3974
题意:一公司有n个人,编号1~n,每个人都有一个直属上司。
两种操作:
1,给x分配任务y,此时,x会将y也分配给他的下属,下属再分配给下属……也就是x下面的人都会放下原先的任务(如果有)而去忙任务y
2,问x当前的任务,若没有则输出-1
思路:给每个任务按时间编号,询问的时候,只需要找到x以及他的所有上司手上时间最靠后的任务就好了。
#include<iostream>#include<cstring>#include<cstdio>using namespace std;#define rep(i,f,t) for(int i = (f),_end = (t); i <= _end; ++i)const int maxn = 50005;int task[maxn];int p[maxn];int t[maxn];int solve(int i){ int j = i; int k = t[i]; while(p[j] != j){ k = max(k, t[p[j]]); j = p[j]; } return task[k];}int main(){ int can,n,m,u,v; task[0] = -1; scanf("%d",&can); rep(cas,1,can){ printf("Case #%d:\n",cas); int tn = 0; rep(i,1,n){ p[i] = i; t[i] = 0; } scanf("%d",&n); rep(i,1,n-1){ scanf("%d%d",&u,&v); p[u] = v; } scanf("%d",&m); while(m--){ char c; int a,b; scanf(" %c",&c); if(c == 'C'){ scanf("%d",&a); int ans = solve(a); printf("%d\n",ans); } else { scanf("%d%d",&a,&b); task[++tn] = b; t[a] = tn; } } } return 0;}
0 0
- HDU 3974 Assign the task [并查集扩展]
- HDU 3974 Assign the task (并查集改编)
- HDU 3974 Assign the task 并查集
- HDU 3974 Assign the task(并查集)
- HDU 3974 Assign the task(树 并查集)
- HDU 3974 Assign the task(并查集)
- 并查集--HDU 3974Assign the task--带权
- HDU 3974 Assign the task 并查集解法
- Assign the task (并查集)
- Assign the task (并查集)
- HDU 3974 Assign the task (并查集&线段树)
- hdu 3974 Assign the task
- hdu 3974 Assign the task
- hdu 3974 Assign the task
- HDU 3974 Assign the task
- HDU 3974 Assign the task
- hdu 3974 Assign the task
- hdu 3974 Assign the task
- Dubbo和Spring集成Demo
- “微服务” 的架构终将成为产品架构上的主流
- 闲聊DTD语法
- play验证码模块的实现
- Reverse Integer
- HDU 3974 Assign the task [并查集扩展]
- sqoop数据导出导入命令
- Ecmascript 标准中的Array.prototype中的函数定义
- HDU ACM 2111 Saving HDU->贪心
- oracle用户目录误删除的恢复
- Java基础:多线程
- C Primer Plus 第十章学习总结……2015.4.30
- hive over hbase方式将文本库数据导入hbase
- 初体验