Sicily 1063 Who's the Boss
来源:互联网 发布:win10rar解压软件下载 编辑:程序博客网 时间:2024/05/20 14:17
这道题的题意有误,错在这一句:In fact, you can be absolutely sure that your immediate boss is the person who earns the least among all the employees that earn more than you and are at least as tall as you are.根据这一句,题目给出的案例二,2003是比2002工资多的人里工资最少的,那么2003即是2002的直接上司。这样就与答案不符,而且也与2003比2002矮矛盾。实际上题目想表达的意思是:员工的工资比他所有的直系上司要低。根据这个意思作法如下。结果能够AC。
#include <iostream>#include <vector>#include <algorithm>#include <map>#include <climits>using namespace std;struct Node { int id; int salary; int height; int boss; vector<int> children;};int subordinatesCount(const vector<Node> &tree, int index) { if (tree[index].children.empty()) return 0; else { int count=0; for (vector<int>::const_iterator iter=tree[index].children.begin(); iter!=tree[index].children.end(); iter++) { count++; count+=subordinatesCount(tree, *iter); } return count; }}int main() { int cases; cin>>cases; while (cases--) { int m, q; cin>>m>>q; vector<Node> tree; map<int, int> table; if (m) {// godtree.push_back(Node());tree[0].id=0;tree[0].salary=INT_MAX;tree[0].height=INT_MAX; while (m--) { tree.push_back(Node()); cin>>tree[tree.size()-1].id >>tree[tree.size()-1].salary >>tree[tree.size()-1].height; } bool moreSalary(Node a, Node b); sort(tree.begin(), tree.end(), moreSalary); // 建立tree里id到索引的映射表 for (int i=0; i<tree.size(); i++) table[tree[i].id]=i; // 构建树 tree[0].boss=-1;// big boss for (int i=1; i<tree.size(); i++) { int boss=i; while (tree[--boss].height<tree[i].height); // until tree[boss].height>=tree[i].height tree[i].boss=boss; tree[boss].children.push_back(i); } } while (q--) { int id; cin>>id; cout<<tree[tree[table[id]].boss].id<<" " <<subordinatesCount(tree, table[id])<<"\n"; } } return 0;}bool moreSalary(Node a, Node b) { return a.salary>b.salary;}/**************************************************************************特殊情况总要加以特别考虑,比如这道题里big boss,它们总是不同于一般情况的逻辑。***************************************************************************/// by wbchou// Jan 31th, 2013
- Sicily 1063 Who's the Boss
- sicily 1063 Who's the boss
- Sicily 1063. Who's the Boss
- sicily 1063. Who's the Boss
- [sicily online]1063. Who's the Boss
- Sicily 1063. Who's the Boss
- sicily 1063.Who's the boss
- Sicily 1063. Who's the Boss
- Sicily 1063. Who's the Boss
- sicily 1063. Who's the Boss
- sicily 1063. Who's the Boss
- 1001. Who's the Boss
- 1063. Who's the Boss
- 1063. Who's the Boss
- Sicily.1063. Who's the Boss(排序,确定上下属关系)
- ZOJ1989 POJ1634 Who's the Boss
- poj 1634 Who's the boss?
- POJ 1634 Who's the boss?
- 设计头文件
- unicode、utf-8、ansi的故事及其相互转换
- 提高网站访问速度的34条军规
- 多 思 慎 言
- 类找不到总结java.lang.ClassNotFoundException
- Sicily 1063 Who's the Boss
- What the fuck life I'm going
- java.lang.NoClassDefFoundError: org/codehaus/groovy/control/CompilationFailedException错误解决方案
- 联想G480a 3230 Win7 操作系统 解决 小键盘问题
- OpenJWeb2.6文档及2.6开源版发布公告
- linux下并行计算
- windows程序员进阶系列:《软件调试》之三:中断和异常
- hadoop集群部署
- 电脑编程是什么