Sicily 1063 Time Limit Exceeded我日

来源:互联网 发布:iptables 关闭udp端口 编辑:程序博客网 时间:2024/04/29 18:20

Constraints

Time Limit: 1 secs, Memory Limit: 32 MB

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

23 3123456 14323 1700000123458 41412 1900000123457 15221 18000001234561234581234574 4200002 12234 1832001200003 15002 1745201200004 18745 1883410200001 24834 1921313200004200002200003200001

Sample Output

123457 00 2123458 1200001 2200004 0200004 00 3

感觉受到了伤害。。。

#include <iostream>#include <stdlib.h>#include <vector>#include <map>#include <algorithm>using namespace std;struct employee{int immediateBoss;int id;int salary;int height;int sub_Count;};bool cmpHeight(employee a, employee b) {return a.height > b.height;}bool cmpSalary(employee a, employee b) {return a.salary > b.salary;}int main() {int n;cin >> (n);while(n--) {int m,q,i,j,k,query;multimap<int, int> result;employee employees[30000];employee tmp[30000];cin >> m >> q;for(i = 0; i < m; i++) {employee tmp;cin >> tmp.id >> tmp.salary >> tmp.height;tmp.sub_Count = 0, tmp.immediateBoss = 0;employees[i] = tmp;}sort(employees, employees + m, cmpHeight);for(j = m - 1; j >= 0; j--) {//sort(employees, employees + j, cmpSalary);int least = 100000000;for(k = j - 1; k >= 0; k--) {if(employees[k].salary >= employees[j].salary && employees[k].height >= employees[j].height) {if(employees[k].salary < least) {least = employees[k].salary;employees[j].immediateBoss = employees[k].id;employees[k].sub_Count += employees[j].sub_Count + 1;}}}//sort(employees, employees+j, cmpHeight);}for(i = 0; i < q; i++) {cin >> query;for(j = 0; j < m; j++) {if(employees[j].id == query) {if(employees[j].immediateBoss != 0)cout << employees[j].immediateBoss << " " << employees[j].sub_Count << endl;elsecout << employees[j].immediateBoss << " " << m - 1 << endl;break;}}} }return 0;}


0 0
原创粉丝点击