zoukankan      html  css  js  c++  java
  • 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[50001];
    
    int main(){
        std::ios::sync_with_stdio(false);
        int i, j, k, t, n, m, u, v, num, tt, caseNum, ttime;
        char cmd;
        caseNum = 0;
        cin >> t;
        while(t--){
            int tim = 0;
            for(i = 1; i <= 50000; ++i){
                a[i].work = -1;
                a[i].time = 0;
                a[i].leader = -1;
            }
            cin >> n;
            for(i = 1; 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 != -1){
                        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 0;
    }
  • 相关阅读:
    rdesktop ERROR: CredSSP: Initialize failed, do you have correct kerberos tgt initialized ? Failed to connect, CredSSP required by server
    nginx 服务器重启命令,关闭
    Libvirt磁盘加密
    qemu-nbd使用教程
    交叉编译Spice-gtk
    通过Python调用Spice-gtk
    远程桌面连接KVM虚拟机
    虚拟创建失败之Dbus调试
    Libvirt代码架构
    Libvirt外部快照
  • 原文地址:https://www.cnblogs.com/wushuaiyi/p/4163048.html
Copyright © 2011-2022 走看看