On the first line of the input is a single positive integer n,telling the number of test scenarios to follow. Each scenariobegins with a line containing two positive integers m and q, wherem (at most 30000) is the number of employees and q (at most 200) isthe number of queries. The following m lines each list an employeeby three integers on the same line: employee ID number (six decimaldigits, the first one of which is not zero), yearly salary in Eurosand finally height in m (1 microm= 10^-6 meters - accuracy isimportant at TALL). The chairperson is the employee that earns morethan anyone else and is also the tallest person in the company.Then there are q lines listing queries. Each query is a singlelegal employee ID.
The salary is a positive integer which is at most 10 000 000. Notwo employees have the same ID, and no two employees have the samesalary. The height of an employee is at least 1 000 000 microm andat most 2 500 000 microm.
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
123457 0 0 2 123458 1 200001 2 200004 0 200004 0 0 3
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
struct Node
{
int ID, salary,height;
int boss; //直属老板的ID
int subCount; // 下属的数量
};
bool cmpBySalary(constNode& s1, const Node& s2) // 薪水比较函数
{
return s1.salary< s2.salary;
}
int main()
{
int T, m, q;
scanf("%d",&T);
Nodedata[30000];
while(T--)
{
scanf("%d%d",&m, &q);
for(int i = 0; i< m; i++)
{
scanf("%d%d%d",&data[i].ID, &data[i].salary,&data[i].height);
data[i].boss =data[i].subCount = 0;
}
sort(data, data+m,cmpBySalary); // 按薪水从低到高排序
for(int i = 0, j; i< m; i++)
for(j = i+1; j< m; j++)
{
if(data[i].height<= data[j].height) //判断老板ID和下属数目
{
data[i].boss =data[j].ID;
data[j].subCount +=data[i].subCount + 1;
break;
}
}
for (int i = 0, j; i< q; i++) // 线性查找
{
int num;
scanf( "%d",&num);
for( j = 0; j< m; j++)
{
if(data[j].ID ==num)
break;
}
printf( "%d %d\n",data[j].boss, data[j].subCount );
}
}
return 0;
}