sicily 1063.Who's the boss
2013-10-17 23:47
459 查看
#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
- [sicily online]1063. Who's the Boss
- sicily 1063 Who's the boss
- 1063. Who's the Boss
- Sicily 1063. Who's the Boss
- ZOJ1989 POJ1634 Who's the Boss
- 2018_2_13_Who's the boss?_层次_排序_思维
- pku 1634 Who's the boss? stl排序+二分查找
- The Art of Intimacy_Personal Boundaries at Work -- Who's the Boss?
- poj 1634 Who's the boss?
- Sicily 1063 Who's the Boss
- POJ 1634 Who's the boss? 笔记
- POJ 1634 Who's the boss?
- (利用树的遍历求解层次性问题8.4.10)POJ 1634 Who's the boss?(求解某一个节点的父亲以及他的孩子的数目)
- POJ 2388 Who's in the Middle
- POJ 2886 Who Gets the Most Candies?(线段树)
- Sicily 1920 Divide The Stones
- [转]How to find who is using / eating up the Virtual Address Space on your SQL Server
- Determine who is monopolizing the CPU
- poj2886 Who Gets the Most Candies?