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 ...
随机推荐
- sql server把一个表中数据复制到另一个表
insert into A(ID,Name,Sex,Address,DID,...) from (select ID,Name,Sex,Address, 5 DID)
- Dijkstra算法求单源最短路径
Description 在每年的校赛里,所有进入决赛的同学都会获得一件很漂亮的t-shirt.但是每当我们的工作人员把上百件的衣服从商店运回到赛场的时候,却是非常累的!所以现在他们想要寻找最短的从商店 ...
- 关于express4不再支持body-parser
express的bodyParser能将表单里的数据格式化,bodyParser原是绑定在express中的,但从express4开始,不在绑定了 如果依然直接使用app.use(express.bo ...
- 框架开发(三)---smarty整合
一 smarty 是什么 Smarty是一个PHP的模板引擎.更明确来说,它可以帮助开发者更好地 分离程序逻辑和页面显示.最好的例子,是当程序员和模板设计师是不同的两个角色的情况,而且 大部分时候都不 ...
- Making your first driver - complete walkthrough(使用VisualDDK)
This article describes how to create, build and debug your first driver using Visual Studio and Visu ...
- Qt信息隐藏(Q_D/Q_Q)介绍——从二进制兼容讲起
http://www.cnblogs.com/SkylineSoft/articles/2046404.html
- Android 中Notification的运用
Notification在手机的运用中是很常见的,比如我们收到一个短信,在我们的通知栏就会显示一个消息的图标用来提示我们,这种我们就可以用Notification来实现.他有很多的用法,比如类似消息的 ...
- Windows Azure Camp---漫步云端,创意无限
不再需要一系列繁杂的网银密码,一键搞定所有的支付:与朋友约会时通过实时分享地理位置迅速找到对方,这些都可以在WindowsAzure平台得以实现.在刚刚结束的2013年微软学生夏令营中,来自全国30所 ...
- [转载]HDFS的'Block'和MapReduce的'Split'之间的关系和区别
http://www.cnblogs.com/xuxm2007/archive/2011/09/01/2162011.html hadoop的分块有两部分,其中第一部分更为人熟知一点. 第一部分就 ...
- Static block start new thread
Static block start new thread public class StaticThreadInit { static{ Threadt = newThread(){ public ...