Sicily-1063
一.题意
一个员工是另外一个员工的老板必须满足的条件是作为老板的员工的薪水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的更多相关文章
- sicily 1063. Who's the Boss
Time Limit: 1sec Memory Limit:32MB Description Several surveys indicate that the taller you are, ...
- sicily 1063. Who's the Boss 排序+递推
#include <cstdio> #include <algorithm> using namespace std; struct Emp{ int id, salary, ...
- sicily 中缀表达式转后缀表达式
题目描述 将中缀表达式(infix expression)转换为后缀表达式(postfix expression).假设中缀表达式中的操作数均以单个英文字母表示,且其中只包含左括号'(',右括号‘)’ ...
- sicily 1934. 移动小球
Description 你有一些小球,从左到右依次编号为1,2,3,...,n. 你可以执行两种指令(1或者2).其中, 1 X Y表示把小球X移动到小球Y的左边, 2 X Y表示把小球X移动到小球Y ...
- codevs 1063 合并果子//优先队列
1063 合并果子 2004年NOIP全国联赛普及组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 题目描述 Description 在一个果园里,多多已经将所有的果 ...
- hdu 1063(java写高精度)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1063 思路:最近刚学了java,然后就迫不及待想试试java写大数的好处了,呵呵,果然是很方便啊! i ...
- 1063. Set Similarity (25)
1063. Set Similarity (25) 时间限制 300 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given ...
- 大数求模 sicily 1020
Search
- Sicily 1510欢迎提出优化方案
这道题我觉得是除1000(A-B)外最简单的题了……不过还是提出一个小问题:在本机用gcc编译的时候我没包括string.h头文件,通过编译,为什么在sicily上却编译失败? 1510. Mispe ...
- lightoj 1063 求割点
题目链接:http://lightoj.com/volume_showproblem.php?problem=1063 #include<cstdio> #include<cstri ...
随机推荐
- GWT工程 —— HostedMode(宿主模式下调试) 所有的运行命令
Unknown argument: -helpGoogle Web Toolkit 1.7.0HostedMode [-noserver] [-port port-number | "aut ...
- BZOJ 1812: [Ioi2005]riv( 树形dp )
树背包, 左儿子右兄弟来表示树, dp(x, y, z)表示结点x, x的子树及x的部分兄弟共建y个伐木场, 离x最近的伐木场是z时的最小代价. 时间复杂度O(N^2*K^2) ----------- ...
- xhprof
#官网下载 http://pecl.php.net/package/xhprof tar zxf xhprof-0.9.2.tgz cd xhprof-0.9.2/extension/ sud ...
- JQuery初识
一.什么是JQuery JQuery官方网站上是这样解释的:JQuery是一个快速简洁的JavaScript库,它可以简化HTML文档的元素遍历.事件处理.动画及Ajax交互,快速开发We ...
- 一周学会Mootools 1.4中文教程:(4)类型
Mootools的类型主要包含下边几部分:String:字符串;Number:数字;Array:数组;Object:对象;Json:;Cookie:. 这也是我们今天的讲述重点.每一种数据类型Mt都为 ...
- 表单元素的submit()方法和onsubmit事件(转)
1.表单元素中出现了name="submit"的元素 2.elemForm.submit();不会触发表单的onsubmit事件 3.动态创建表单时遇到的问题 表单元素拥有subm ...
- jquery.validate 一些技巧
1.Validator.element() Validates a single element, returns true if it is valid, false otherwise. http ...
- oralce dubugs
1,The listener supports no services 2,invalid specification for system parameter LOCAL_LISTENER crea ...
- iOS加载HTML, CSS代码
NSString *strHTML = @"<div style=\"text-align:center;\"><img src=\"/Upl ...
- [每日一题] OCP1z0-047 :2013-08-22 正则表达式---[^Ale|ax.r$]'
正确答案:DE 一.Oracle正则表达式的相关知识点 '[^Ale|ax.r$]': ^:匹配行的开始字符 $:匹配行的结束字符 []:方括号表示指定一个匹配列表,该列表匹配列表中显示的任何表达式. ...