Sicily-1063
生活随笔
收集整理的這篇文章主要介紹了
Sicily-1063
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一.題意
一個員工是另外一個員工的老板必須滿足的條件是作為老板的員工的薪水salary必須大于這個員工,而且作為老板的員工的身高height要大于等于這個員工。首先按照薪水的多少從小到大進行排序,然后找每一個員工的直屬老板。注意老板的下屬的數量為其下屬的下屬之和。
二.用結構體。為了方便查詢再加設一個按id號排序的數組。
三. 注意員工老板的后代包括這些員工后代的和。每次vector都要清空一次。
四. 代碼
1 // 2 // main.cpp 3 // sicily-1063 4 // 5 // Created by ashley on 14-10-13. 6 // Copyright (c) 2014年 ashley. All rights reserved. 7 // 8 9 #include <iostream> 10 #include <vector> 11 #include <algorithm> 12 using namespace std; 13 typedef struct 14 { 15 int idNumber; 16 int salary; 17 int height; 18 int bossId; 19 int subordinates; 20 }employee; 21 vector<employee> allEmployees; 22 employee sortByID[1000000]; 23 int query[200]; 24 bool compare(employee left, employee right) 25 { 26 return left.salary < right.salary; 27 } 28 int main(int argc, const char * argv[]) 29 { 30 int cases; 31 int employeeCounter, queryCounter; 32 int id, sal, hei; 33 cin >> cases; 34 while (cases--) { 35 allEmployees.clear(); 36 cin >> employeeCounter >> queryCounter; 37 for (int i = 0; i < employeeCounter; i++) { 38 cin >> id >> sal >> hei; 39 allEmployees.push_back(employee{id, sal, hei, 0, 0}); 40 } 41 for (int i = 0; i < queryCounter; i++) { 42 cin >> query[i]; 43 } 44 sort(allEmployees.begin(), allEmployees.begin() + employeeCounter, compare); 45 //找boss 46 for (int i = 0; i < employeeCounter; i++) { 47 int key = -1; 48 for (int j = i + 1; j < employeeCounter; j++) { 49 if (allEmployees[j].height >= allEmployees[i].height) { 50 key = j; 51 break; 52 } 53 } 54 if (key != -1) { 55 allEmployees[i].bossId = allEmployees[key].idNumber; 56 allEmployees[key].subordinates = allEmployees[key].subordinates + allEmployees[i].subordinates + 1; 57 } 58 sortByID[allEmployees[i].idNumber] = allEmployees[i]; 59 } 60 for (int i = 0; i < queryCounter; i++) { 61 cout << sortByID[query[i]].bossId << " " << sortByID[query[i]].subordinates << endl; 62 } 63 } 64 return 0; 65 }?
轉載于:https://www.cnblogs.com/ashley-/p/4151817.html
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的Sicily-1063的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 关于android中的armeabi、a
- 下一篇: 用什么软件测试路由器,软件测试路由器系统