sicily 1063. Who's the Boss

Time Limit: 1sec    Memory Limit:32MB

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 microm= 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 microm and at most 2 500 000 microm.

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

 Copy sample input to clipboard

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
#include <iostream>
#include <algorithm>
#include <cstdio>

using namespace std;

struct Info {
    Info(int i = 0, int s = 0, int h = 0): identify(i), salary(s), height(h), boss(0), subNum(0) { }
    int identify;
    int salary;
    int height;
    int boss;
    int subNum;
}employeeInfo[30010];

bool cmp (const Info &a, const Info &b) {
    return a.salary < b.salary;
}

// bool isBoss(const Info &a, const Info &b) {
//     return a.height >= b.height;
// }

int main(int argc, char *argv[])
{
    int n;
    int m, q;
    scanf("%d", &n);
    while (n--) {
        scanf("%d%d", &m, &q);
        int identify, salary, height;
        for (int i = 0; i != m; ++i) {
            scanf("%d%d%d", &identify, &salary, &height);
            employeeInfo[i] = Info(identify, salary, height);
        }
        sort(employeeInfo, employeeInfo + m, cmp);  // 根据薪水排序

        for (int i = 0; i != m - 1; i++) {
            for (int j = i + 1; j <= m - 1; j++) {
                if (employeeInfo[j].height >= employeeInfo[i].height) {  // 本来这里是一个比较函数的,也即注释里面的 isBoss,但是这样就超时了。没想明白原因
                                                                         // 按照编译器的优化,这里编译器应该会将这个函数变为 inline 的,
                                                                         // 可能平台的编译器版本比较低吧,暂时没时间看 sicily 源码,下次看看...
                    employeeInfo[j].subNum++;
                    employeeInfo[i].boss = employeeInfo[j].identify;
                    employeeInfo[j].subNum += employeeInfo[i].subNum;  // 自己的下级数加上下级的下级数,就是总下级数
                    break;
                }
            }
        }
        for (int i = 0; i != q; ++i) {
            scanf("%d", &identify);
            for (int j = 0; j != m; j++) {
                if (employeeInfo[j].identify == identify) {
                    printf("%d %d\n", employeeInfo[j].boss, employeeInfo[j].subNum);
                    break;
                }
            }
        }
    }

    return 0;
}

sicily 1063. Who's the Boss

时间: 2024-10-07 05:31:47

sicily 1063. Who's the Boss的相关文章

编程题目分类(剪辑)

1. 编程入门 2. 数据结构 3. 字符串 4. 排序 5. 图遍历 6. 图算法 7. 搜索:剪枝,启发式搜索 8. 动态规划/递推 9. 分治/递归 10. 贪心 11. 模拟 12. 算术与代数 13. 组合问题 14. 数论 15. 网格,几何,计算几何 [编程入门] PC 110101, uva 100, The 3n+1 problem, 难度 1 PC 110102, uva 10189, Minesweeper, 难度 1 PC 110103, uva 10137, The T

Deep Learning Enables You to Hide Screen when Your Boss is Approaching

https://github.com/Hironsan/BossSensor/ 背景介绍 学生时代,老师站在窗外的阴影挥之不去.大家在玩手机,看漫画,看小说的时候,总是会找同桌帮忙看着班主任有没有来. 一转眼,曾经的翩翩少年毕业了,新的烦恼来了,在你刷知乎,看视频,玩手机的时候,老板来了! 不用担心,不用着急,基于最新的人脸识别+手机推送做出的BossComing.老板站起来的时候,BossComing会通过人脸识别发现老板已经站起来,然后通过手机推送发送通知“BossComing”,并且震动告

11153 kill boss

11153 kill boss 时间限制:1000MS  内存限制:65535K提交次数:1090 通过次数:340 题型: 编程题   语言: G++;GCC Description Acmer最近喜欢上了玩某个游戏,这个游戏的格斗风格是以格挡,招架,攻击为主,acmer最近打一个boss打了几遍,还是没有打赢,但是经过几次失败后, acmer大概摸清了boss的出招规律,所以她做好了相应的出招式,acmer被boss砍掉n滴血后会挂掉,对应的只要acmer在挂掉前砍掉boss m滴血,acm

数论 + 容斥 - HDU 4059 The Boss on Mars

The Boss on Mars Problem's Link Mean: 给定一个整数n,求1~n中所有与n互质的数的四次方的和.(1<=n<=1e8) analyse: 看似简单,倘若自己手动推公式的话,还是需要一定的数学基础. 总的思路:先求出sum1=(1^4)+(2^4)+...(n^4),再求出sum2=(1~n中与n不互质的数的四次方的和),answer=sum1-sum2. 如何求sum1呢? 有两种方法: 1.数列差分.由于A={Sn}={a1^4+a2^4+...an^4}

假如BOSS给了PM一个不靠谱的需求

假如BOSS给了一个PM不靠谱的需求,那么站在PM的角度上,我会怎么处理呢?在知乎上看了好多达人以及同行的真知灼见,自己也是有一番小的思考,这里做一个总结吧 其实,这种不靠谱的产生的最主要的原因无非是所处的位置和立场不同,因而会发出不同的声音. 作为一个BOSS,更可能是从当前整个市场的行情,走向去看问题,觉得我们应该做一个XXX产品,实现XXX需求,然后达到XXX目标. 作为一个PM,更多的是考虑一个产品满足这种需求所需要的成本,实现细节以及"性价比",如果PM再厉害点的话,可能技术

hdu 1063 Exponentiation

http://acm.hdu.edu.cn/showproblem.php?pid=1063 1 import java.math.BigDecimal; 2 import java.util.*; 3 public class Main { 4 public static void main(String []args) 5 { 6 Scanner cin=new Scanner(System.in); 7 BigDecimal r,mutil; 8 String ans; 9 int n;

浅谈游戏中BOSS设计的思路

对于大多数游戏来说,BOSS在其设计上都有着不可替代的作用,也是玩家印象最为深刻的一部分.近期自己也有在做BOSS的设计工作,有一些心得想要分享一下: 1.明确BOSS的设计目的 在设计之初,我们一定要想明白,设计这个BOSS的目的在于什么,一场BOSS战往往需要花费巨大的成本来制作:美术需要花费大量时间.经历制作与其相关的多种美术资源:开发需要编写大量代码来实现BOSS相对复杂的行为,以及实现对应动画.特效及相关音频资源.一场失败的BOSS战设计,不仅会花费大量的成本,还会令玩家感到十分反感.

Sicily 1146:Lenny&#39;s Lucky Lotto(dp)

题意:给出N,M,问有多少个长度为N的整数序列,满足所有数都在[1,M]内,并且每一个数至少是前一个数的两倍.例如给出N=4, M=10, 则有4个长度为4的整数序列满足条件: [1, 2, 4, 8], [1, 2, 4, 9], [1, 2, 4, 10], [1, 2, 5, 10] 分析:可用动态规划解题,假设dp[i][j],代表满足以整数i为尾数,长度为j的序列的个数(其中每一个数至少是前一个数的两倍).那么对于整数i,dp[i][j] 等于所有dp[k][j-1]的和,其中k满足:

hdu4059---The Boss on Mars(容斥原理+前n项的4次方和)

Problem Description On Mars, there is a huge company called ACM (A huge Company on Mars), and it's owned by a younger boss. Due to no moons around Mars, the employees can only get the salaries per-year. There are n employees in ACM, and it's time for