POJ 1634 Who's the boss?

Who‘s the boss?

Time Limit: 5000MS   Memory Limit: 30000K
Total Submissions: 2773   Accepted: 1142

Description

Several surveys indicate that the taller you are, the higher you can climb the corporate ladder. At TALL Enterprises Inc. this "de facto standard" has been properly formalized: your boss is always at least as tall as you are. Furthermore, you can safely assume
that your boss earns a bit more than you do. In fact, you can be absolutely sure that your immediate boss is the person who earns the least among all the employees that earn more than you and are at least as tall as you are. Furthermore, if you are the immediate
boss of someone, that person is your subordinate, and all his subordinates are your subordinates as well. If you are nobody‘s boss, then you have no subordinates. As simple as these rules are, many people working for TALL are unsure of to whom they should
be turning in their weekly progress report and how many subordinates they have. Write a program that will help in determining for any employee who the immediate boss of that employee is and how many subordinates they have. Quality Assurance at TALL have devised
a series of tests to ensure that your program is correct. These test are described below.

Input

On the first line of the input is a single positive integer n, telling the number of test scenarios to follow. Each scenario begins with a line containing two positive integers m and q, where m (at most 30000) is the number of employees and q (at most 200)
is the number of queries. The following m lines each list an employee by three integers on the same line: employee ID number (six decimal digits, the first one of which is not zero), yearly salary in Euros and finally height in μm (1 μm = 10-6 meters
- accuracy is important at TALL). The chairperson is the employee that earns more than anyone else and is also the tallest person in the company. Then there are q lines listing queries. Each query is a single legal employee ID.

The salary is a positive integer which is at most 10 000 000. No two employees have the same ID,and no two employees have the same salary. The height of an employee is at least 1 000 000 μm and at most 2 500 000 μm.

Output

For each employee ID x in a query output a single line with two integers y k, separated by one space character, where y is the ID of x‘s boss, and k is the number of subordinates of x. If the query is the ID of the chairperson, then you should output 0 as the
ID of his or her boss (since the chairperson has no immediate boss except, possibly, God).

Sample Input

2
3 3
123456 14323 1700000
123458 41412 1900000
123457 15221 1800000
123456
123458
123457
4 4
200002 12234 1832001
200003 15002 1745201
200004 18745 1883410
200001 24834 1921313
200004
200002
200003
200001

Sample Output

123457 0
0 2
123458 1
200001 2
200004 0
200004 0
0 3

Source

Northwestern Europe 2003

ACcode:

#include <map>
#include <queue>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#define maxn 30010
using namespace std;
int hash[1000000];
int stack[maxn],top=0;
struct woker{
    int id;
    int wage;
    int height;
    int boss;
    int nsub;
    void in(){
        scanf("%d%d%d",&id,&wage,&height);
        boss=0;
        nsub=1;
    }
    void on(){
        printf("id %d wage %d height %d boss %d nsub %d\n",id,wage,height,boss,nsub);
    }
}my[maxn];
bool cmp(woker a,woker b){
    return a.wage<b.wage;
}
int main(){
    int loop,n,m;
    scanf("%d",&loop);
    while(loop--){
        scanf("%d%d",&n,&m);
        for(int i=0;i<n;++i)my[i].in();
        sort(my,my+n,cmp);
        for(int i=0;i<n;++i){
            hash[my[i].id]=i;
        }
        top=0;
        for(int i=0;i<n;i++){
            while(top&&my[stack[top-1]].height<=my[i].height){
      				my[stack[top-1]].boss=my[i].id;
      				my[i].nsub+=my[stack[top-1]].nsub;
      				top--;
      			}
      			stack[top++]=i;
        }
        /**for(int i=0;i<n;++i){
            printf("%d",i);
            my[i].on();
        }**/
        int t,k;
        for(int i=0;i<m;++i){
            scanf("%d",&t);
            k=hash[t];
            printf("%d %d\n",my[k].boss,my[k].nsub-1);
        }
    }
    return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

POJ 1634 Who's the boss?

时间: 2024-10-09 02:42:56

POJ 1634 Who's the boss?的相关文章

poj 1634

题意:给你m个员工,和n次的查询. 每个员工有他独立的id,收入,和身高 上司的收入一定大于下属的收入,身高也是大于等于下属的. 每个公司的头头没有上司,上司的编号为0,,同时他也是收入最多身高最高的人. n次查询. 对于每一次查询,输出它对应的上司的其下属的个数. Memory: 4572K Time: 766MS Language: C++ Result: Accepted #include <iostream> #include <stdio.h> #include <

POJ - 3249 Test for Job (DAG+topsort)

Description Mr.Dog was fired by his company. In order to support his family, he must find a new job as soon as possible. Nowadays, It's hard to have a job, since there are swelling numbers of the unemployed. So some companies often use hard tests for

Test for Job (poj 3249 记忆化搜索)

Language: Default Test for Job Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 9733   Accepted: 2245 Description Mr.Dog was fired by his company. In order to support his family, he must find a new job as soon as possible. Nowadays, It's

poj 1265 Area (Pick定理+求面积)

链接:http://poj.org/problem?id=1265 Area Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4969   Accepted: 2231 Description Being well known for its highly innovative products, Merck would definitely be a good target for industrial espionag

POJ 1265 Area

Area Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4713   Accepted: 2129 Description Being well known for its highly innovative products, Merck would definitely be a good target for industrial espionage. To protect its brand-new resear

poj 1265 Area 面积+多边形内点数

Area Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5861   Accepted: 2612 Description Being well known for its highly innovative products, Merck would definitely be a good target for industrial espionage. To protect its brand-new resear

ACM训练方案-POJ题目分类

ACM训练方案-POJ题目分类 博客分类: 算法 ACM online Judge 中国: 浙江大学(ZJU):http://acm.zju.edu.cn/ 北京大学(PKU):http://acm.pku.edu.cn/JudgeOnline/ 杭州电子科技大学(HDU):http://acm.hdu.edu.cn/ 中国科技大学(USTC):http://acm.ustc.edu.cn/ 北京航天航空大学(BUAA)http://acm.buaa.edu.cn/oj/index.php 南京

POJ 3249 Test for Job (记忆化搜索 好题)

Test for Job Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 9512   Accepted: 2178 Description Mr.Dog was fired by his company. In order to support his family, he must find a new job as soon as possible. Nowadays, It's hard to have a job

转载:poj题目分类(侵删)

转载:from: POJ:http://blog.csdn.net/qq_28236309/article/details/47818407 按照ac的代码长度分类(主要参考最短代码和自己写的代码) 短代码:0.01K–0.50K:中短代码:0.51K–1.00K:中等代码量:1.01K–2.00K:长代码:2.01K以上. 短:1147.1163.1922.2211.2215.2229.2232.2234.2242.2245.2262.2301.2309.2313.2334.2346.2348