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. ...
随机推荐
- poj3074-Sodoku
解数独. 分析 考虑如何把数独解合法的条件转化为经典的01精确覆盖: 每个格子只能填一个数,1-9 每一列刚好填了1-9 每一行刚好填了1-9 每个九宫格刚好填了1-9 也就是说,每个格子,列,行,九 ...
- 《转》vue-cli的webpack模板项目配置文件注释
一.文件结构 本文主要分析开发(dev)和构建(build)两个过程涉及到的文件,故下面文件结构仅列出相应的内容. ├─build │ ├─build.js │ ├─check-versions.js ...
- hdu 1281 棋盘游戏 (二分匹配)
棋盘游戏 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- [NOI.AC省选模拟赛3.31] 星辰大海 [半平面交]
题面 传送门 思路 懒得解释了......也是比较简单的结论 但是自己看到几何就退缩了...... 下周之内写一个计算几何的学习笔记! Code #include<iostream> #i ...
- POJ3304:Segments——题解
http://poj.org/problem?id=3304 题目大意:给n条线段,求是否存在一条直线,将所有线段投影到上面,使得所有投影至少交于一点. ——————————————————————— ...
- BZOJ2657:[ZJOI2012]旅游——题解
http://www.lydsy.com/JudgeOnline/problem.php?id=2657 https://www.luogu.org/problemnew/show/P2610 到了难 ...
- CF498D:Traffic Jams in the Land——题解
https://vjudge.net/problem/CodeForces-498D http://codeforces.com/problemset/problem/498/D 题面描述: 一些国家 ...
- GDI & GDI+
GDI GDI绘图中的映射模式CDC::SetMapMode() GDI编程小结 GDI+ GDI+小例子 关于GDI+ GDI+编程小结
- NOIP2015Day2T3运输计划(二分+树上差分)
做了这么多NOIPTG的题,这是唯一 一道一眼秒的T3(有时候T2还不会做QAQ)... 题目大意就不说了QWQ 思路大概是:啊最大值最小化,来个二分.检验mid的话,显然就是用最长路径减去所有边权& ...
- java 实现多个接口 方法重名的解决办法——内部类
package com.kk.innerClass; /** * 通过内部类实现接口 * 解决多个接口中方法重名问题 * */interface Machine { void run();} clas ...