根据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. chroot命令

    CHROOT就是Change Root,也就是改变程序执行时所参考的根目录位置.通过chroot机制来更改某个进程所能看到的根目录,即将某进程限制在指定目录中,保证该进程只能对该目录及其子目录的文件有 ...

  2. 盘点:移动服务 #AzureChat

    感谢大家帮助我们顺利推出史无前例的 #AzureChat.移动服务和 Notification Hub 是 Windows Azure 平台上令人振奋的服务.我们很高兴能借这次在线讨论的机会,倾听各位 ...

  3. web.xml中servlet, bean, filter, listenr 加载顺序汇总

    最终得出结果:先 listener >> filter >> servlet >> spring 所以,如果过滤器中要使用到 bean,可以将spring 的加载 ...

  4. C++ Primer 学习笔记_75_模板与泛型编程 --模板定义

    模板与泛型编程 --模板定义 引言: 所谓泛型程序就是以独立于不论什么特定类型的方式编写代码.使用泛型程序时,我们须要提供详细程序实例所操作的类型或值. 模板是泛型编程的基础.使用模板时能够无须了解模 ...

  5. Objective-c Category(类别)

    category是Objective-c里面最常用的功能之一. category可以为已经存在的类增加方法,而不需要增加一个子类. 类别接口的标准语法格式如下: #import "类名.h& ...

  6. 邮件发送 emailsend .net开发

    protected void Button1_Click(object sender, EventArgs e) { MailSender.Send("lizihong3@163.com&q ...

  7. 自动分组+合并完整的sql脚本

    BEGIN#前提:指定字符串长度为8字符定长#逻辑:循环8次,比对2个字符串相同索引位置下的数值大小,并取结果最大值.#示例:merge1(输入参数source1,输入参数source2,输出结果re ...

  8. CSS样式表基础知识、样式表的分类及选择器

    一.CSS基本概念: CSS(Cascading Style Sheet,叠层样式表),作用是美化HTML网页. /*注释区域*/    此为注释语法 二.样式表的分类 1.内联样式表(和html联合 ...

  9. BZOJ 4143 The Lawyer

           这道题看起来很吓人,但事实上看懂后会发现,其根本没有任何技术含量,做这道题其实要考虑的就是每天最早结束的一场的结束时间以及最晚开始的一场的开始时间,如果结束时间早于开始时间,那么OK就这 ...

  10. OC-nonatomic和atomic相关

    1.原子和非原子属性1.1>OC在定义属性时又nonatomic和atomic两种选择(1)atomic:原子属性,为setter方法加锁(默认就是atomic)(2)nonatomic:非原子 ...