根据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. 高质量程序设计指南C/C++语言——C++/C程序设计入门(4)

    *switch结构的break语句只是一个“jmp”指令,其作用就是跳到switch结构的结尾处 *标准C++/C语言提供3种循环:do/while.while和for,它们都在条件表达式为TRUE( ...

  2. phome_ecms_news 数据表字段解释(新闻系统模型-主表)

    http://www.phome.net/doc/manual/extend/html/dbdoc/index.html 字段名 类型 解释 附加说明 id int(11) 信息ID   classi ...

  3. Python单元测试:unittest使用简介

    一.概述 本文介绍python的单元测试框架unittest,这是Python自带的标准模块unittest.unittest是基于java中的流行单元测试框架junit设计的,其功能强大且灵活,对于 ...

  4. HDU 1276 士兵队列训练问题

    模拟题,学了一下list it=li.erase(it):指向删除后的第一个元素 #include <cstdio> #include <list> using namespa ...

  5. find the most comfortable road(并差集,找差值最小的权值)

    find the most comfortable road Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ...

  6. FZU Problem 2169 shadow

    http://acm.fzu.edu.cn/problem.php?pid=2169 题目大意: S王国有N个城市,有N-1条道路.王都为编号1的城市.叛军驻扎在很多城市.除了王都外有K个城市有军队, ...

  7. gridview的高级使用

      后台数据 using System; using System.Collections.Generic; using System.Linq; using System.Web; using Sy ...

  8. python之高阶函数编程

    在这篇文章中我指出两点: 第一:系统函数可以被覆盖 比如: a=abs(-10) print a 10 但是,如果把函数本身赋值给变量呢? f = abs f <built-in functio ...

  9. openstack第1天

    入门openstack题外篇 老实说,我在写这篇文章的时候,对云的了解还是比较模糊的,也许是刚接触,不管怎样 总得写点什么,写完之后也许数月之后,感觉写的不是那么好,到时候在做修该吧! 今天我们就提一 ...

  10. (转)内核线程对象--Event事件对象

    在所有的内核对象中,事件内核对象是个最基本的对象.事件能够通知一个操作已经完成. 客户机和一个服务器,它们之间需要互相进行通信例子(vs2008 ) 事件内核对象的组成 一个使用计数(与所有内核对象一 ...