Sicily 1063. Who ' s the Boss

Source: Internet
Author: User

1063. Who's The Boss Constraints

Time limit:1 secs, Memory limit:32 MB

Description

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

Input

on The first line of the input was a single positive integer n, telling the number of test scenarios T o follow. Each scenario begins with a line containing-positive integers m and q, where m (at most 30000) is the number of employ EES and Q (at most) is the number of queries. The following m lines each list a employee by three integers on the same line:employee ID number (six decimal digits, th E first one of which is no zero), yearly salary in Euros and finally height in m (1 microm= 10^-6 meters-accuracy are IM Portant at TALL). The Chairperson is the employee of this earns more than anyone else and was also the tallest person in the company. Then there is Q lines listing queries. Each query was a single legal employee ID.

The salary is a positive integer which are at 10 000 000. No. Employees has the same ID, and no and employees have the same salary. The height of an employee are at least 1 microm and at most 2 microm.

Output

For the employee ID x in a query output a single line with the 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 and then you should output 0 as the ID of his or her boss (since the Chairperson ha s no immediate boss except, possibly, God).

Sample Input
23 3123456 14323 1700000123458 41412 1900000123457 15221 18000001234561234581234574 4200002 12234 1832001200003 15002 1745 201200004 18745 1883410200001) 24834 1921313200004200002200003200001
Sample Output
123457 00 2123458 1200001 2200004 0200004 00 3

Very good a problem, find the direct boss and subordinate number, this 0.49s version:

#include <iostream> #include <algorithm> #include <stdio.h>using namespace std;struct people {int id, Salary, height, boss, subordinates;} P[30005];bool cmp_salary (const people& A, const people& b) {//Sort by salary, easy to find bosses and subordinates return a.salary <= b.salary;} BOOL cmp_id (const people& A, const people &b) {//Sort by ID, easy to find return a.id <= b.id;}        int find (int target, int front, int back) {//two min. to find ID if (front <= back) {int mid = (front + back)/2;        if (p[mid].id = = target) return mid;        else if (target < p[mid].id) return find (target, front, mid-1);    else return find (target, mid + 1, back); } else return 0;}        int main () {int case_num, p_num, Q_num, I, J, Target, POS;        scanf ("%d", &case_num);        while (case_num--) {scanf ("%d%d", &p_num, &q_num); for (i = 0; i < P_num; i++) {scanf ("%d%d%d", &p[i].id, &p[i].salary, &p[i].heigHT);            P[i].boss = 0;        p[i].subordinates = 0;  } sort (p, p + p_num, cmp_salary);//Sort by salary for (i = 0; i < P_num; i++) {for (J = i + 1; J < P_num; J + +) {if (p[j].height >= p[i].height) {//The first one found is the direct boss p[j].subordinates + = P[i].subo                    Rdinates + 1;//Find the owner of the number of subordinates equal to the current number of employees plus the employee himself p[i].boss = p[j].id;                break;//remember break, otherwise the number of subordinates will have a lot of repetition}}} sort (p, p + p_num, cmp_id);//Sort by ID            while (q_num--) {scanf ("%d", &target);            pos = find (target, 0, p_num-1);        printf ("%d%d\n", P[pos].boss, p[pos].subordinates);                              }} return 0;}


Sicily 1063. Who ' s the Boss

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.