HDU 3974 Assign the task 简单搜索
根据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 简单搜索的更多相关文章
- HDU 3974 Assign the task(简单线段树)
Assign the task Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDU 3974 Assign the task 并查集/图论/线段树
Assign the task Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?p ...
- HDU 3974 Assign the task
Assign the task Problem Description There is a company that has N employees(numbered from 1 to N),ev ...
- HDU 3974 Assign the task 暴力/线段树
题目链接: 题目 Assign the task Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...
- HDU 3974 Assign the task (DFS序 + 线段树)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3974 给你T组数据,n个节点,n-1对关系,右边的是左边的父节点,所有的值初始化为-1,然后给你q个操 ...
- 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 ...
- HDU 3974 Assign the task 并查集
http://acm.hdu.edu.cn/showproblem.php?pid=3974 题目大意: 一个公司有N个员工,对于每个员工,如果他们有下属,那么他们下属的下属也是他的下属. 公司会给员 ...
- hdu 3974 Assign the task(线段树)
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=3974 题意:给定一棵树,50000个节点,50000个操作,C x表示查询x节点的值,T x y表示更 ...
- hdu 3974 Assign the task (线段树+树的遍历)
Description There is a company that has N employees(numbered from 1 to N),every employee in the comp ...
随机推荐
- LintCode-乱序字符串
题目描述: 给出一个字符串数组S,找到其中所有的乱序字符串(Anagram).如果一个字符串是乱序字符串,那么他存在一个字母集合相同,但顺序不同的字符串也在S中. 注意事项 所有的字符串都只包含小写字 ...
- Oracle的三种高可用集群方案
浏览了一下Oracle官方的网页以及非官方的ppt,简单了解了一下Oracle提供的高可用方案. 主要有三种: 1. RAC RAC, Real Application Clusters 多个Ora ...
- QT太多的内容和模块,怎么办?
我有个问题,QT可以做许多不同的开源项目,而且每个QT新版本都那么内容,感觉学不过来.用不过来那么我们还应该学习和使用其它语言吗? 如果回答,在需要的时候学习,那么这句话意味着,这几年你基本上就局限于 ...
- C#共享内存实例 附源码
原文 C#共享内存实例 附源码 网上有C#共享内存类,不过功能太简单了,并且写内存每次都从开头写.故对此进行了改进,并做了个小例子,供需要的人参考. 主要改进点: 通过利用共享内存的一部分空间(以下称 ...
- CodeIgniter结合Bootstrap
CodeIgniter-Bootstrap结合了 cI和bootstrap的长处,一个专注于服务器端,一个专注于ui,这个把2个结合起来了.框架地址: http://www.andyhawthorne ...
- 转:CI配置SMARTY
1.到相应站点下载Smarty的源码包:2.将源码包里面的libs文件夹copy到CI的项目目录下面的libraries文件夹下,并重命名为Smarty:3.在目录 application/libra ...
- Flex LinkButton鼠标划过出现下划线
在LinkButton中 textDecoration属性设置label的是否有下划线装饰,属性值分为"none","underline" 代码如下------ ...
- TMT行业分析师
诚聘英才 - 传媒梦工场 TMT行业分析师 工作经验: 2年以上 发布日期: 2013-01-04 最低学历: 本科 管理经验: 否 工作性质: 全职 招聘人数: 1人 职位类别: 金融 ...
- Ext.MessageBox.Show使用Progress
在此之前,先添加引用:以下引用方式仅供参考:由于我的extjs文件夹放在script文件夹下 <link href="~/Scripts/extjs/resources/ext-the ...
- Android中的一些基础知识(一)
翻译自这里,并做了部分修改. 什么是Android? Android是为移动设备提供的软件,它包括操作系统.中间件.和一些关键的应用程序.应用程序执行它自己的进程和在Dalvik虚拟机中的实例. An ...