poj 1634 简单数据结构
2016-07-20 16:40
316 查看
Who's the boss?
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 μm = 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 μm and at most 2 500 000 μm.
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
Sample Output
题意:给出m个员工的 ID salary high
一个员工A的直接上司是那些薪水大于A,并且身高>=A的人中薪水最少的一个
主席CEO的薪水最高,且身高也是最高的
求题目所给出的的某一个编号的上司和下属个数
题解:把薪水从小到大排序
然后扫一遍计算他的直接的上司,并且叠加下属个数,break
注意:这里一定要是 i 从1 开始,因为当没有上司的时候就是 i=0 ,然后输出 对应的值 0 这个0 是系统默认的
Time Limit: 5000MS | Memory Limit: 30000K | |
Total Submissions: 2882 | Accepted: 1174 |
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 μm = 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 μm and at most 2 500 000 μm.
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
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
Sample Output
123457 0 0 2 123458 1 200001 2 200004 0 200004 0 0 3
题意:给出m个员工的 ID salary high
一个员工A的直接上司是那些薪水大于A,并且身高>=A的人中薪水最少的一个
主席CEO的薪水最高,且身高也是最高的
求题目所给出的的某一个编号的上司和下属个数
题解:把薪水从小到大排序
然后扫一遍计算他的直接的上司,并且叠加下属个数,break
注意:这里一定要是 i 从1 开始,因为当没有上司的时候就是 i=0 ,然后输出 对应的值 0 这个0 是系统默认的
#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; const int maxx=30005; struct people { int id; int salary; int high; }a[maxx]; int id_num[1000000];//id和排好序后的号对应 int father[maxx];//直接上司的编号 int num[maxx];//手下个数 int cmp(people x,people y) { return x.salary<y.salary; } int main() { int T,m,n; scanf("%d",&T); while(T--) { scanf("%d%d",&m,&n); for(int i=1;i<=m;i++) num[i]=1; memset(father,0,sizeof(father)); for(int i=1;i<=m;i++) scanf("%d%d%d",&a[i].id,&a[i].salary,&a[i].high); sort(a+1,a+m+1,cmp); for(int i=1;i<=m;i++){ id_num[a[i].id]=i;//上叙一定要有等号 for(int j=i+1;j<=m;j++) if(a[j].high>=a[i].high){ father[i]=j; num[j]+=num[i]; break; } } for(int i=1;i<=n;i++){ int id; scanf("%d",&id); int temp=id_num[id]; printf("%d %d\n",a[father[temp]].id,num[temp]-1); } } return 0; }
相关文章推荐
- 线性表知识点总结一(第三天)
- 数据结构之—图
- 【慢速学数据结构】树的遍历
- SDUT 3334 数据结构实验之栈七:出栈序列判定
- 数据结构(脑洞题,BIT):COGS 2394. 比赛
- 经典排序算法 集锦
- HeadFirstJava——14_数据结构
- 山东理工OJ 2122 数据结构实验之链表七:单链表中重复元素的删除
- 数据结构C语言描述———快速排序算法详解
- 数据结构C语言——用二叉链表示二叉树
- 数据结构C语言描述———用顺序队列判断回文数
- java数据结构与算法学习1-排序
- 数据结构-串
- 【慢速学数据结构】图篇
- 复习(数据结构):栈:c语言:动态数组
- SDUT 3333 数据结构实验之栈六:下一较大值(二)
- 数据结构
- C语言描述数据结构———封装DLL
- hdu2570_迷瘴
- SDUT 2143 数据结构实验之栈四:括号匹配