一.题意

一个员工是另外一个员工的老板必须满足的条件是作为老板的员工的薪水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. 获取文件数据流+叠加byte数组(给byte数组加包头包尾)

    OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "(*.mp4)|*.mp4|(*.*)|*.*"; ofd.Res ...

  2. C++输出中文字符(转)

    C++输出中文字符 1. cout 场景1: 在源文件中定义 const char* str = "中文" 在 VC++ 编译器上,由于Windows环境用 GBK编码,所以字符串 ...

  3. Linux命令之修改主机名

    ubuntu永久修改主机名 1.查看主机名 在Ubuntu系统中,快速查看主机名有多种方法: 其一,打开一个GNOME终端窗口,在命令提示符中可以看到主机名,主机名通常位于“@”符号后: 其二,在终端 ...

  4. Html页面加回滚

    <div class="top-box"> <img src=" class="youlink-img" /><br / ...

  5. JQurey获取radio和checkbox的值

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Web2.aspx.cs&q ...

  6. JAVA并发,线程异常捕获

    由于线程的特性,当我们启动了线程是没有办法用try catch捕获异常的,如下例: package com.xt.thinks21_2; import java.util.concurrent.Exe ...

  7. Java 初始化的个人理解

    先说明一下由来吧,下面是同学的一道笔试题,以前感觉对java初始化也是了解一二的,结果,看到这题泪奔了,不会...上网查,自己添加println,总算是能把自己讲明吧了,不知理解的对不对,先记录下吧, ...

  8. RedisTemplate.htm

    http://docs.spring.io/spring-data/redis/docs/current/api/org/springframework/data/redis/core/RedisTe ...

  9. 灰度直方图及处理“cvQueryHistValue_1D”: 找不到标识符”的问题(上)

    // HIstogram.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include "opencv2/opencv.hpp ...

  10. 排序算法 - 快速排序(Quick Sort)

    算法思想 快速排序是C.R.A.Hoare于1962年提出的一种划分交换排序.它采用了一种分治的策略,通常称其为分治法(Divide-and-ConquerMethod). (1) 分治法的基本思想  ...