ZOJ1989 POJ1634 Who's the Boss
来源:互联网 发布:网络主持人是做什么 编辑:程序博客网 时间:2024/05/23 23:47
可以暴力过,但是起码要好几百ms
这里我设置了上帝哨兵,同时使用迭代搜索。
先按工资排序。然后对于x,如果x的前一个人x-1的身高不低于x,则x-1就是x的上司(boss[x]=x-1);否则,我们就要测试x-1的上司boss[x-1]是否x的上司,一直迭代到上帝哨兵(上帝哨兵肯定是所有人的上司)。
/******************************************************************************* # Author : Neo Fung # Email : neosfung@gmail.com # Last modified: 2012-06-11 21:30 # Filename: ZOJ1989 POJ1634 Who's the Boss.cpp # Description : ******************************************************************************/#ifdef _MSC_VER// #define DEBUG#define _CRT_SECURE_NO_DEPRECATE#endif#include <fstream>#include <stdio.h>#include <iostream>#include <string.h>#include <string>#include <limits.h>#include <algorithm>#include <math.h>#include <numeric>#include <functional>#include <ctype.h>using namespace std;const int kMAX=30010;const double kEPS=10E-6;struct NODE{int id,salary,height;bool operator<(const NODE &t) const{return salary>t.salary;}}nodes[kMAX];int map[1000000],subordinates[kMAX],boss[kMAX];int inline FindBoss(const int &y,const int &x){if(!x)return 0;if(nodes[y].height>=nodes[x].height)// 如果y是x的上司return y;else return FindBoss(boss[y],x);// 否则测试y的上司是x的上司}int main(void){#ifdef DEBUG freopen("../stdin.txt","r",stdin);freopen("../stdout.txt","w",stdout); #endif int n,m,ncase=1,tmp;scanf("%d",&ncase);nodes[0].id=0;nodes[0].salary=nodes[0].height=(1<<30);// 上帝哨兵while(ncase--){scanf("%d%d",&n,&m);for(int i=1;i<=n;++i)scanf("%d%d%d",&nodes[i].id,&nodes[i].salary,&nodes[i].height);sort(nodes+1,nodes+1+n);for(int i=0;i<=n;++i)map[nodes[i].id]=i;memset(subordinates,0,sizeof(subordinates));boss[0]=0;for(int i=1;i<=n;++i)boss[i]=FindBoss(i-1,i);for(int i=n;i>=1;--i)subordinates[boss[i]]+=(1+subordinates[i]);while(m--){scanf("%d",&tmp);int x=nodes[boss[map[tmp]]].id;printf("%d %d\n",x,subordinates[map[tmp]]);}}return 0;}
- ZOJ1989 POJ1634 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
- sicily 1063. Who's the Boss
- poj 1634 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
- POJ 1634 Who's the boss?
- sicily 1063. Who's the Boss
- sicily 1063. Who's the Boss
- POJ 1634 Who's the boss? 笔记
- 使用response实现文件的下载
- 课程设计1 -------------- 王爽 汇编语言
- 一个简单的指向函数的指针示例
- 终于可以开始写博客了6.11-6.12
- 通过归档永久存储数据
- ZOJ1989 POJ1634 Who's the Boss
- 用JavaScript操纵HTML5的本地音频
- IE6下PNG图背景透明解决办法(IE6解决PNG透明)
- [Silverlight入门系列]实现局部元素全屏(Element部分全屏)
- down_interruptible函数和down函数的问题
- struts2通配符映射
- 自动编译.9.png
- hostapd的radius/eap server代码分析(2)-hostapd配置
- 使用Settings Bundle为程序添加设置项