#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;
struct node
{
int id;
int salary;
int height ;
};
bool comp(node const & a,node const & b)
{
return a.salary < b.salary ;
}
int main()
{
int n,m,p;
scanf("%d",&n);
while(n--)
{
vector<node> val;
val.clear();
scanf("%d %d",&m,&p);
for(int i=0;i<m;i++)
{
node temp;
scanf("%d %d %d",&temp.id,&temp.salary,&temp.height);
val.push_back(temp);
}
sort(val.begin(),val.end(),comp);
while(p--)
{
int id = -1,goalSalary = -1,goalHeight = -1,boss = 0,sNum=0;
scanf("%d",&id);
//find boss
for(int i=0;i<val.size();i++)
{
if(val[i].id == id)
{
goalSalary = val[i].salary;
goalHeight = val[i].height;
}
else if(goalSalary > 0 && goalHeight > 0 &&
val[i].salary > goalSalary && val[i].height >= goalHeight)
{
boss = val[i].id;
break;
}
}
printf("%d ",boss);
//find subordinate
for(int i=0;i<val.size();i++)
{
if(val[i].id == id)
{
break;
}
else
{
if(val[i].salary < goalSalary && val[i].height <= goalHeight)//若前面所有i的身高都比goal身高矮,则即使i不是goal的下属,也是i到goal中j的下属,而j肯定是goal的下属,所以i也是goal的下属
{
sNum++;
}
//i的身高大于goalheight,即i之前的员工都是i的下属,而i与goal之间没有上下属关系。
else
{
sNum =0;
}
}
}
printf("%d\n",sNum);
}
}
return 0;
}
sicily 1063.Who's the boss
最新推荐文章于 2015-11-13 11:12:00 发布