根据Rex 的思路才知道可以这么写。

题目意思还是很好理解的,就是找到当前雇员最近的任务。

做法是,可以开辟一个 tim 变量,每次有雇员得到昕任务时候 ++tim

然后取寻找最近的任务的时候写一个搜索就可以

核心代码:

                while(num != -1){
num = a[num].leader;
if(ttime < a[num].time){
ans = a[num].work;
ttime = a[num].time;
}
}

Source code:

//#pragma comment(linker, "/STACK:16777216") //for c++ Compiler
#include <stdio.h>
#include <iostream>
#include <cstring>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#define ll long long
#define Max(a,b) (((a) > (b)) ? (a) : (b))
#define Min(a,b) (((a) < (b)) ? (a) : (b))
#define Abs(x) (((x) > 0) ? (x) : (-(x))) using namespace std; const int INF = 0x3f3f3f3f;
struct sc{
int work, leader, time;
}a[]; int main(){
std::ios::sync_with_stdio(false);
int i, j, k, t, n, m, u, v, num, tt, caseNum, ttime;
char cmd;
caseNum = ;
cin >> t;
while(t--){
int tim = ;
for(i = ; i <= ; ++i){
a[i].work = -;
a[i].time = ;
a[i].leader = -;
}
cin >> n;
for(i = ; i < n; ++i){
cin >> u >> v;
a[u].leader = v;
}
cout << "Case #" << ++caseNum << ":" << endl;
cin >> m;
while(m--){
cin >> cmd;
if(cmd == 'C'){
cin >> num;
ttime = a[num].time;
int ans = a[num].work;
while(num != -){
num = a[num].leader;
if(ttime < a[num].time){
ans = a[num].work;
ttime = a[num].time;
}
}
cout << ans << endl;
} else{
cin >> num >> tt;
a[num].work = tt;
a[num].time = ++tim;
}
}
}
return ;
}

HDU 3974 Assign the task 简单搜索的更多相关文章

  1. HDU 3974 Assign the task(简单线段树)

    Assign the task Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  2. HDU 3974 Assign the task 并查集/图论/线段树

    Assign the task Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?p ...

  3. HDU 3974 Assign the task

    Assign the task Problem Description There is a company that has N employees(numbered from 1 to N),ev ...

  4. HDU 3974 Assign the task 暴力/线段树

    题目链接: 题目 Assign the task Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...

  5. HDU 3974 Assign the task (DFS序 + 线段树)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3974 给你T组数据,n个节点,n-1对关系,右边的是左边的父节点,所有的值初始化为-1,然后给你q个操 ...

  6. HDU 3974 Assign the task(DFS序+线段树单点查询,区间修改)

    描述There is a company that has N employees(numbered from 1 to N),every employee in the company has a ...

  7. HDU 3974 Assign the task 并查集

    http://acm.hdu.edu.cn/showproblem.php?pid=3974 题目大意: 一个公司有N个员工,对于每个员工,如果他们有下属,那么他们下属的下属也是他的下属. 公司会给员 ...

  8. hdu 3974 Assign the task(线段树)

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=3974 题意:给定一棵树,50000个节点,50000个操作,C x表示查询x节点的值,T x y表示更 ...

  9. hdu 3974 Assign the task (线段树+树的遍历)

    Description There is a company that has N employees(numbered from 1 to N),every employee in the comp ...

随机推荐

  1. KVO 的使用和举例

    KVO(key-value Observer),通过命名可以联想到,一个监视着监视着键值配对,让一个对象A来监视另一个对象B中的键值,一旦B中的受监视键所对应的值发生了变化,对象A会进入一个回调函数, ...

  2. USB3.0 和usb 2.0的区别

    USB3.0拥有10倍于USB2.0的速度,可惜DIY“江湖”险恶,如果咱们不掌握如何识别USB3.0的方法,很容易被JS忽悠.何况,USB3.0主板不等于USB3.0机箱,很多朋友在选购时都忽略了一 ...

  3. MultiView空间例子

    CSS代码: body { font-size:11pt; font-family:宋体; } .mainTitle { font-size:11pt; font-weight:bold; font- ...

  4. mongodb 学习初探

    1.去mongodb 官方下载 http://www.mongodb.org/downloads 2.下载php的mongodb扩展 http://files.cnblogs.com/lsl8966/ ...

  5. [dfs+水] hdu 4462 Scaring the Birds

    题意: N*N的矩阵中有M个点能够放稻草人.且给覆盖距离R 每一个稻草人能覆曼哈顿距离R以内的点 问最少须要多少个稻草人 思路: 由于范围非常小,直接能够暴力 注意稻草人所在的位置是不须要被覆盖的 代 ...

  6. Implement custom foreach function in C#

    http://msdn.microsoft.com/en-us/library/System.Collections.IEnumerator.aspx http://support.microsoft ...

  7. 在GridView控件里面绑定DropDownList控件

    参考链接: http://www.aspsnippets.com/Articles/Populate-DropDownList-with-Selected-Value-in-EditItemTempl ...

  8. 工具篇-MAT(Memory Analyzer Tool)

    --- layout: post title: 工具篇-MAT(Memory Analyzer Tool) description: 让内存泄漏无所遁形 2015-10-08 category: bl ...

  9. Java之对象序列化和反序列化

    一.对象序列化和反序列化存在的意义: 当你创建对象,只要你需要,他就一直存在,但当程序结束,对象就会消失,但是存在某种情况,如何让程序在不允许的状态,仍然保持该对象的信息.并在下次程序运行的时候使用该 ...

  10. java数据结构与算法值优先级队列

    一.优先级队列 什么是优先级队列:优先级队列是一种比栈和队列更加常用的一种数据结构.在优先级队列中,数据项按照关键字的值有序.数据项插入到队列中时,会按照顺序插入到合适的位置,用来保证队列的顺序. 生 ...