一.题意

一个员工是另外一个员工的老板必须满足的条件是作为老板的员工的薪水salary必须大于这个员工,而且作为老板的员工的身高height要大于等于这个员工。首先按照薪水的多少从小到大进行排序,然后找每一个员工的直属老板。注意老板的下属的数量为其下属的下属之和。

二.用结构体。为了方便查询再加设一个按id号排序的数组。

三. 注意员工老板的后代包括这些员工后代的和。每次vector都要清空一次。

四. 代码

 //
// main.cpp
// sicily-1063
//
// Created by ashley on 14-10-13.
// Copyright (c) 2014年 ashley. All rights reserved.
// #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef struct
{
int idNumber;
int salary;
int height;
int bossId;
int subordinates;
}employee;
vector<employee> allEmployees;
employee sortByID[];
int query[];
bool compare(employee left, employee right)
{
return left.salary < right.salary;
}
int main(int argc, const char * argv[])
{
int cases;
int employeeCounter, queryCounter;
int id, sal, hei;
cin >> cases;
while (cases--) {
allEmployees.clear();
cin >> employeeCounter >> queryCounter;
for (int i = ; i < employeeCounter; i++) {
cin >> id >> sal >> hei;
allEmployees.push_back(employee{id, sal, hei, , });
}
for (int i = ; i < queryCounter; i++) {
cin >> query[i];
}
sort(allEmployees.begin(), allEmployees.begin() + employeeCounter, compare);
//找boss
for (int i = ; i < employeeCounter; i++) {
int key = -;
for (int j = i + ; j < employeeCounter; j++) {
if (allEmployees[j].height >= allEmployees[i].height) {
key = j;
break;
}
}
if (key != -) {
allEmployees[i].bossId = allEmployees[key].idNumber;
allEmployees[key].subordinates = allEmployees[key].subordinates + allEmployees[i].subordinates + ;
}
sortByID[allEmployees[i].idNumber] = allEmployees[i];
}
for (int i = ; i < queryCounter; i++) {
cout << sortByID[query[i]].bossId << " " << sortByID[query[i]].subordinates << endl;
}
}
return ;
}

Sicily-1063的更多相关文章

  1. sicily 1063. Who's the Boss

    Time Limit: 1sec    Memory Limit:32MB  Description Several surveys indicate that the taller you are, ...

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

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

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

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

  4. sicily 1934. 移动小球

    Description 你有一些小球,从左到右依次编号为1,2,3,...,n. 你可以执行两种指令(1或者2).其中, 1 X Y表示把小球X移动到小球Y的左边, 2 X Y表示把小球X移动到小球Y ...

  5. codevs 1063 合并果子//优先队列

    1063 合并果子 2004年NOIP全国联赛普及组  时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石    题目描述 Description 在一个果园里,多多已经将所有的果 ...

  6. hdu 1063(java写高精度)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1063 思路:最近刚学了java,然后就迫不及待想试试java写大数的好处了,呵呵,果然是很方便啊! i ...

  7. 1063. Set Similarity (25)

    1063. Set Similarity (25) 时间限制 300 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given ...

  8. 大数求模 sicily 1020

        Search

  9. Sicily 1510欢迎提出优化方案

    这道题我觉得是除1000(A-B)外最简单的题了……不过还是提出一个小问题:在本机用gcc编译的时候我没包括string.h头文件,通过编译,为什么在sicily上却编译失败? 1510. Mispe ...

  10. lightoj 1063 求割点

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1063 #include<cstdio> #include<cstri ...

随机推荐

  1. 匹配图片src正则

    preg_match_all('#<img.*?src="([^"]*)"[^>]*>#i', $xstr, $match); /** * 获取图片sr ...

  2. pushViewController自定义动画

    实现的主要代码如下: CATransition *transition = [CATransition animation]; transition.duration = 1.0f; transiti ...

  3. Objective-C的hook方案(一): Method Swizzling

    Objective-C的hook方案(一):  Method Swizzling 转自:http://blog.csdn.net/yiyaaixuexi/article/details/9374411 ...

  4. Javascript闭包概念剖析

    某种情况下,函数调用依然持有对其原始定义的作用域的引用,这个引用就叫做闭包. function foo(){ var a = 2; function bar(){ console.log(a); } ...

  5. c++ build options(important)

    The C runtime library  4 versions: Multi-threaded (/MT) Multi-threaded Debug (/MTd) Multi-threaded D ...

  6. Spring学习之常用注解(转)

    使用注解来构造IoC容器 用注解来向Spring容器注册Bean.需要在applicationContext.xml中注册<context:component-scan base-package ...

  7. Hive Map 端OOM 异常

    怪异现象:数据量不大,且不是Reduce端OOM,是Map端OOM Map Task运行的时候数据流中包含了非法字符例如:EOF.NOP等东西,导致BufferedReader读取和StreamDec ...

  8. hadoop搭建杂记:Linux下JDK环境变量的设置(三种配置环境变量的方法)

    Linux下JDK环境变量的设置(三种配置环境变量的方法) Linux下JDK环境变量的设置(三种配置环境变量的方法) ①修改/etc/profile文件 如果你的计算机仅仅作为开发使用时推荐使用这种 ...

  9. ThinkPHP第二十五天(自动完成、用户名密码PHP正则、移位或加密函数)

    1.ThinkPHP自动完成功能 跟昨天的自动验证功能类似,也是需要在自定义的UserModel类,进行使用. 使用方法:定义$_auto属性 $_auto = array( array(完成字段,完 ...

  10. eclipse注解快捷键

    Search 功能:全局文件内容搜索快捷键: Ctrl + H -------------------------------------------------------------------- ...