题目;http://acm.hdu.edu.cn/showproblem.php?pid=5493

题目大意,t组数据,n个人,n行每行分别是人的身高和这个人的左边或右边比他高的人的个数,输出符合条件的字典序最小的人排列的序列.

想到线段树就很好做了,记录空位,按顺序安放人的身高,和原来做的题目很相似

 #include<cstdio>
#include<algorithm>
using namespace std;
struct point {
int h,k;
bool operator <(const point & a)const
{
return h<a.h;
}
};
point yj[];
int res[];
struct node{
int l,r,x;
};
node tree[*];
void build(int i,int left,int right)
{
tree[i].l=left;tree[i].r=right;
if (left==right)
{
tree[i].x=;
return ;
}
int mid=(left+right)>>;
build(i<<,left,mid);
build(i<<|,mid+,right);
tree[i].x=tree[i<<].x+tree[i<<|].x;
}
void update(int i,int ans,int num)
{
if (tree[i].l==tree[i].r)
{
tree[i].x=;
res[tree[i].l]=num;
return ;
}
int mid=(tree[i].l+tree[i].r)>>;
if (ans<=tree[i<<].x) update(i<<,ans,num);
else update(i<<|,ans-tree[i<<].x,num);
tree[i].x=tree[i<<].x+tree[i<<|].x;
}
int main()
{
int t,i,q=,n;
scanf("%d",&t);
while (t--)
{
scanf("%d",&n);
for (i=;i<=n;i++)
scanf("%d %d",&yj[i].h,&yj[i].k);
sort(yj+,yj+n+);
build(,,n);
int flag=;
for (i=;i<=n;i++)
{
int m=n-i;
int temp=m-yj[i].k;
if (temp<)
{
flag=;
break;
}
if (temp>yj[i].k) update(,yj[i].k+,yj[i].h);
else update(,temp+,yj[i].h);
}
printf("Case #%d: ",q++);
if (flag) printf("impossible\n");
else
{
for (i=;i<=n;i++)
{
if (i!=n) printf("%d ",res[i]);
else printf("%d\n",res[i]);
}
}
}
return ;
}

最新文章

  1. 使用js_md5加密密码
  2. tornado学习笔记14 HTTP1ServerConnection分析
  3. AngularJS的学习笔记(二)
  4. IIS 7 的 500 內部錯誤
  5. [转]Hibernate3如何解决n+1 selects
  6. Linux Shell脚本教程
  7. 《CSS3秘笈》备忘录
  8. jquery index()方法
  9. UIImage拉伸显示
  10. 《Linear Algebra and Its Applications》-chaper2-矩阵的逆
  11. 使用pip install 或者easy_install安装Python的各种包出现cc failed with exit status 1
  12. Ubuntu中nfs服务器安装与配置
  13. git 拉取远程分之到本地
  14. PHP中简单的图形处理
  15. 基于visual Studio2013解决C语言竞赛题之0406数列求和
  16. STM32学习笔记(三)——外部中断的使用
  17. 引水入城[NOI2010 ]
  18. Android开发 PopupWindow弹窗调用第三方地图(百度,高德)实现导航功能
  19. 『流畅的Python』第10章笔记_序列类型
  20. ESLint 使用方法

热门文章

  1. 吴裕雄 15-MySQL LIKE 子句
  2. vue --轮播图
  3. location search的中文加密
  4. java-学习6
  5. vue-concise-slider 一个轻量的vue幻灯片组件
  6. div 光标处插入内容
  7. Gradle安装和在IDEA使用 基本操作
  8. unity延时方法
  9. cdnbest补充api
  10. vue打包后,接口请求404的完美解决方案