Time Limit: 1sec    Memory Limit:32MB 
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
aaarticlea/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAARABIDASIAAhEBAxEB/8QAGAABAAMBAAAAAAAAAAAAAAAAAAMFBwT/xAAlEAACAQQCAQMFAAAAAAAAAAABAgMABAURBiESIjFBMjZxdbP/xAAYAQACAwAAAAAAAAAAAAAAAAAAAwEEBf/EABsRAQEAAgMBAAAAAAAAAAAAAAEAAgMEEyFh/9oADAMBAAIRAxEAPwDQeRW+SyVnctBIkiiScOk87qm0ciP0aZWA8dkEDZA2fcGPCWPI+PXkUt3GIcQjkyQxTGdtMrAhUVQO5CraVd/UB1pa7cnHmbaW5hjxEktoZJJGulnjChWYsT4lvLoHvr3B1vommvuQYaSe/jGSxrW9yXEiCWIiTe9eWohvs/LH8n5ocDh9jlnsER+zt+9wDE9G0uKWO4hSaGRJIpFDI6MCrKewQR7ilVfFPs7B/r4P5rStB8ZJW9KUqIlKUoi//9k=" alt="" /> Copy sample input to clipboard 
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
#include <iostream>
#include <algorithm>
#include <cstdio> using namespace std; struct Info {
Info(int i = , int s = , int h = ): identify(i), salary(s), height(h), boss(), subNum() { }
int identify;
int salary;
int height;
int boss;
int subNum;
}employeeInfo[]; bool cmp (const Info &a, const Info &b) {
return a.salary < b.salary;
} // bool isBoss(const Info &a, const Info &b) {
// return a.height >= b.height;
// } int main(int argc, char *argv[])
{
int n;
int m, q;
scanf("%d", &n);
while (n--) {
scanf("%d%d", &m, &q);
int identify, salary, height;
for (int i = ; i != m; ++i) {
scanf("%d%d%d", &identify, &salary, &height);
employeeInfo[i] = Info(identify, salary, height);
}
sort(employeeInfo, employeeInfo + m, cmp); // 根据薪水排序 for (int i = ; i != m - ; i++) {
for (int j = i + ; j <= m - ; j++) {
if (employeeInfo[j].height >= employeeInfo[i].height) { // 本来这里是一个比较函数的,也即注释里面的 isBoss,但是这样就超时了。没想明白原因
// 按照编译器的优化,这里编译器应该会将这个函数变为 inline 的,
// 可能平台的编译器版本比较低吧,暂时没时间看 sicily 源码,下次看看...
employeeInfo[j].subNum++;
employeeInfo[i].boss = employeeInfo[j].identify;
employeeInfo[j].subNum += employeeInfo[i].subNum; // 自己的下级数加上下级的下级数,就是总下级数
break;
}
}
}
for (int i = ; i != q; ++i) {
scanf("%d", &identify);
for (int j = ; j != m; j++) {
if (employeeInfo[j].identify == identify) {
printf("%d %d\n", employeeInfo[j].boss, employeeInfo[j].subNum);
break;
}
}
}
} return ;
}

sicily 1063. Who's the Boss的更多相关文章

  1. sicily 1063. Who's the Boss 排序+递推

    #include <cstdio> #include <algorithm> using namespace std; struct Emp{ int id, salary, ...

  2. hdu4059 The Boss on Mars(差分+容斥原理)

    题意: 求小于n (1 ≤ n ≤ 10^8)的数中,与n互质的数的四次方和. 知识点: 差分: 一阶差分: 设  则    为一阶差分. 二阶差分: n阶差分:     且可推出    性质: 1. ...

  3. (三)Netty源码学习笔记之boss线程处理流程

    尊重原创,转载注明出处,原文地址:http://www.cnblogs.com/cishengchongyan/p/6160194.html  本文我们将先从NioEventLoop开始来学习服务端的 ...

  4. 跨界玩AR,迪奥、Hugo Boss等知名奢侈品牌将制造AR眼镜

    Snapchat因为阅后即焚消息应用而被人所熟知,前段时间这家公司拓展主要业务,未来将不再只有消息应用,还有款名为"Spectacles"的AR太阳镜.内置了一个摄像头,戴上之后即 ...

  5. 大BOSS随时都会到来

    郑昀(微博:http://weibo.com/yunzheng) 去年在上市前后,我不止一次跟大家说过如下内容: 我们这帮兄弟第一精通业务,第二有丰富的战斗经验和规范,你们都是中流砥柱,都要带兵打仗. ...

  6. iOS开发之功能模块--高仿Boss直聘的IM界面交互功能

    本人公司项目属于社交类,高仿Boss直聘早期的版本,现在Boss直聘界面风格,交互风格都不如Boss直聘以前版本的好看. 本人通过iPhone模拟器和本人真机对聊,将完成的交互功能通过Mac截屏模拟器 ...

  7. iOS开发之功能模块--高仿Boss直聘的常用语的开发

    首先上Boss直聘的功能界面截图,至于交互请读者现在Boss直聘去交互体验:     本人的公司项目要高仿Boss直聘的IM常用语的交互功能,居然花费了我前后17个小时完成,这回自己测试了很多遍,代码 ...

  8. sicily 中缀表达式转后缀表达式

    题目描述 将中缀表达式(infix expression)转换为后缀表达式(postfix expression).假设中缀表达式中的操作数均以单个英文字母表示,且其中只包含左括号'(',右括号‘)’ ...

  9. 方法构造和方法重载之奥特曼与大boss之战

    知识点的总结: 1.类中的方法分为两类:1.普通方法: 2.构造方法. 2.构造方法的格式:  public 类名(数据类型  参数名,...){ } 3.构造方法的用途:  1.实例化对象.  2. ...

随机推荐

  1. 【bzoj4580】[Usaco2016 Open]248 区间dp

    题目描述 Bessie likes downloading games to play on her cell phone, even though she does find the small t ...

  2. 推荐算法相关总结表(包括DM)

    推荐算法总结表 表1 推荐算法分类 个性化推荐算法分类 启发式算法 基于模型 基于内容 TF-IDF 聚类 最大熵 相似度度量 贝叶斯分类 决策树 神经网络 专家系统 知识推理 协同过滤 K近邻 聚类 ...

  3. 转:概率主题模型简介 --- ---David M. Blei所写的《Introduction to Probabilistic Topic Models》的译文

    概率主题模型简介 Introduction to Probabilistic Topic Models      转:http://www.cnblogs.com/siegfang/archive/2 ...

  4. 在@Async注解下RequestContextHolder.getRequestAttributes() 获得null的情况

    我们有的时候会在service层获取request填充一些诸如用户名和IP地址等信息,这个时候如果不想从Controller层传request,可以在service直接使用 HttpServletRe ...

  5. [BZOJ3380] [USACO2004 Open]Cave Cows 1 洞穴里的牛之一

    Description ​ 很少人知道其实奶牛非常喜欢到洞穴里面去探险. ​ 洞窟里有N(1≤N≤100)个洞室,由M(1≤M≤1000)条双向通道连接着它们.每对洞室间 至多只有一条双向通道.有K( ...

  6. BZOJ5335:[TJOI2018]智力竞赛——题解

    https://www.lydsy.com/JudgeOnline/problem.php?id=5335 小豆报名参加智力竞赛,他带上了n个好朋友作为亲友团一块来参加比赛. 比赛规则如下: 一共有m ...

  7. 洛谷 P2757 [国家集训队]等差子序列 解题报告

    P2757 [国家集训队]等差子序列 题目描述 给一个\(1\)到\(N\)的排列\(\{A_i\}\),询问是否存在 \[1 \le p_1<p_2<p_3<p_4<p_5& ...

  8. Vue语法笔记

    Vue.js 的核心是一个允许采用简洁的模板语法来声明式的将数据渲染进 DOM: 事件监听:v-on 指令绑定一个事件监听器  缩写[@]   v-on:click 用户输入,绑定数据:v-model ...

  9. 我们自己写的solr查询的代码作为search项目中的dao

    我们自己写的solr查询的代码作为search项目中的dao,但是启动时会报错: 其实就是说 searchServiceImpl 中我们 Autowired 的 SearchDao 类 spring ...

  10. Better Linux Disk Caching & Performance with vm.dirty_ratio & vm.dirty_background_ratio

    In previous posts on vm.swappiness and using RAM disks we talked about how the memory on a Linux gue ...