sicily 1063. Who's the Boss
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 Sample Output
123457 0 |
#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的更多相关文章
- sicily 1063. Who's the Boss 排序+递推
#include <cstdio> #include <algorithm> using namespace std; struct Emp{ int id, salary, ...
- hdu4059 The Boss on Mars(差分+容斥原理)
题意: 求小于n (1 ≤ n ≤ 10^8)的数中,与n互质的数的四次方和. 知识点: 差分: 一阶差分: 设 则 为一阶差分. 二阶差分: n阶差分: 且可推出 性质: 1. ...
- (三)Netty源码学习笔记之boss线程处理流程
尊重原创,转载注明出处,原文地址:http://www.cnblogs.com/cishengchongyan/p/6160194.html 本文我们将先从NioEventLoop开始来学习服务端的 ...
- 跨界玩AR,迪奥、Hugo Boss等知名奢侈品牌将制造AR眼镜
Snapchat因为阅后即焚消息应用而被人所熟知,前段时间这家公司拓展主要业务,未来将不再只有消息应用,还有款名为"Spectacles"的AR太阳镜.内置了一个摄像头,戴上之后即 ...
- 大BOSS随时都会到来
郑昀(微博:http://weibo.com/yunzheng) 去年在上市前后,我不止一次跟大家说过如下内容: 我们这帮兄弟第一精通业务,第二有丰富的战斗经验和规范,你们都是中流砥柱,都要带兵打仗. ...
- iOS开发之功能模块--高仿Boss直聘的IM界面交互功能
本人公司项目属于社交类,高仿Boss直聘早期的版本,现在Boss直聘界面风格,交互风格都不如Boss直聘以前版本的好看. 本人通过iPhone模拟器和本人真机对聊,将完成的交互功能通过Mac截屏模拟器 ...
- iOS开发之功能模块--高仿Boss直聘的常用语的开发
首先上Boss直聘的功能界面截图,至于交互请读者现在Boss直聘去交互体验: 本人的公司项目要高仿Boss直聘的IM常用语的交互功能,居然花费了我前后17个小时完成,这回自己测试了很多遍,代码 ...
- sicily 中缀表达式转后缀表达式
题目描述 将中缀表达式(infix expression)转换为后缀表达式(postfix expression).假设中缀表达式中的操作数均以单个英文字母表示,且其中只包含左括号'(',右括号‘)’ ...
- 方法构造和方法重载之奥特曼与大boss之战
知识点的总结: 1.类中的方法分为两类:1.普通方法: 2.构造方法. 2.构造方法的格式: public 类名(数据类型 参数名,...){ } 3.构造方法的用途: 1.实例化对象. 2. ...
随机推荐
- hdu 1688 Sightseeing (最短路径)
Sightseeing Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- 【题解】洛谷9月月赛加时赛 —— Never·island
有趣有趣~ヾ(✿゚▽゚)ノ真的很有意思的一道dp题!感觉可以提供很多非常有意思的思路~ 现场打的时候考虑了很久,但并没有做出来,主要还是卡在了两个地方:1.考虑到按照端点来进行dp,但没有办法将两个端 ...
- BZOJ1016:[JSOI2008]最小生成树计数——题解
https://www.lydsy.com/JudgeOnline/problem.php?id=1016 现在给出了一个简单无向加权图.你不满足于求出这个图的最小生成树,而希望知道这个图中有多少个不 ...
- BZOJ1269 [AHOI2006]文本编辑器editor 【82行splay】
1269: [AHOI2006]文本编辑器editor Time Limit: 10 Sec Memory Limit: 162 MB Submit: 4633 Solved: 1782 [Sub ...
- jquery实现拖拽进度条并显示百分比
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xht ...
- Codeforces Round #337 (Div. 2) A水
A. Pasha and Stick time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- How to configue session timeout in Hive
This article explains how to configure the following settings in Hive:hive.server2.session.check.int ...
- Windows常用shell命令大全(转)
[Windows常用shell命令大全] 基于鼠标操作的后果就是OS界面外观发生改变, 就得多花学习成本.更主要的是基于界面引导Path与命令行直达速度是难以比拟的.另外Geek很大一部分是键盘控,而 ...
- [Leetcode] LRU 算法实现
Design and implement a data structure for Least Recently Used (LRU) cache. It should support the fol ...
- js的alert抛出之后怎么让页面停止执行?
方法: 1.如果是form的submit提交,如果要停止,则返回false:如果提交,则返回true就行了. 2.如果是手工跳转的方式,则如果要停止,则不执行跳转代码:如果要提交,则执行跳转代码 示例 ...