hdu 5493 (2015合肥网赛) Queue
题目;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 ;
}
hdu 5493 (2015合肥网赛) Queue的更多相关文章
- hdu 5491(2015合肥网赛)The Next
题目;http://acm.hdu.edu.cn/showproblem.php?pid=5491 题意就是,T组测试数据.然后L,S1,S2.L的二进制中有x个1,x满足 S1<=x< ...
- hdu 5475(2015上海网赛) An easy problem
题目;http://acm.hdu.edu.cn/showproblem.php?pid=5475 题意就是给X赋初值1,然后给Q个操作,每个操作对应一个整数M:如果操作是1则将X乘以对应的M,如果是 ...
- hdu 5455 (2015沈阳网赛 简单题) Fang Fang
题目;http://acm.hdu.edu.cn/showproblem.php?pid=5455 题意就是找出所给字符串有多少个满足题目所给条件的子串,重复的也算,坑点是如果有c,f以外的字符也是不 ...
- hdu 5461(2015沈阳网赛 简单暴力) Largest Point
题目;http://acm.hdu.edu.cn/showproblem.php?pid=5461 题意就是在数组中找出a*t[i]*t[i]+b*t[j]的最大值,特别注意的是这里i和i不能相等,想 ...
- hdu 5459(2015沈阳网赛) Jesus Is Here
题目;http://acm.hdu.edu.cn/showproblem.php?pid=5459 题意 给出一组字符串,每个字符串都是前两个字符串相加而成,求第n个字符串的c的各个坐标的差的和,结果 ...
- hdu 5443 (2015长春网赛G题 求区间最值)
求区间最值,数据范围也很小,因为只会线段树,所以套了线段树模板=.= Sample Input3110011 151 2 3 4 551 21 32 43 43 531 999999 141 11 2 ...
- ACM学习历程—HDU5490 Simple Matrix (数学 && 逆元 && 快速幂) (2015合肥网赛07)
Problem Description As we know, sequence in the form of an=a1+(n−1)d is called arithmetic progressio ...
- 2015合肥网络赛 HDU 5489 Removed Interval LIS+线段树(树状数组)
HDU 5489 Removed Interval 题意: 求序列中切掉连续的L长度后的最长上升序列 思路: 从前到后求一遍LIS,从后往前求一遍LDS,然后枚举切开的位置i,用线段树维护区间最大值, ...
- 2015合肥网络赛 HDU 5492 Find a path 动归
HDU 5492 Find a path 题意:给你一个矩阵求一个路径使得 最小. 思路: 方法一:数据特别小,直接枚举权值和(n + m - 1) * aver,更新答案. 方法二:用f[i][j] ...
随机推荐
- effective C++学习一(仅供个人学习记录,本文摘录effective C++)
条款 1:尽量用 const 和 inline 而不用#define #define ASPECT_RATIO 1.653 编译器会永远也看不到 ASPECT_RATIO 这个符号名,因为在源码进 ...
- IE 浏览器的兼容性列表设置
打开 IE 浏览器 IE8 为例如:
- 吴裕雄 python oracle子查询的用法(3)
import cx_Oracle conn = cx_Oracle.connect("scott/admin@localhost:1521/orcl")cursor = conn. ...
- supervisord 进程管家
s supervisor supervisor管理进程,是通过fork/exec的方式将这些被管理的进程当作supervisor的子进程来启动,所以我们只需要将要管理进程的可执行文件的路径添加到sup ...
- Ubuntu系统下手动释放内存
有时候,像mongo这种,对内存只吃不吐的,我们要手动释放一下. drop_caches的详细文档如下:Writing to this will cause the kernel to drop cl ...
- SpringMVC包括哪些组件
1 映射器 1.1作用:Handlermapping根据url查找Handler 2 适配器 2.1作用:HandlerAdapter执行Handler 3 解析器 3.1作用:View ...
- python基础入门学习2
python 整体注释:选中所有然后CTRL+? 运算符 + - * / ** % // 布尔值 true 真 False 假 !=不等于 <>不等于 算数运算,赋值运算,比较运 ...
- centos 7 下 TFTP服务器安装
一.介绍 TFTP(Trivial File Transfer Protocol,简单文件传输协议)),是一个基于UDP 协议 69端口 实现的用于在客户机和服务器之间进行简单文件传输的协议提供不复杂 ...
- HandlerMapping和HandlerAdapter配置须知
---------------------siwuxie095 HandlerMapping 和 HandlerAdapter 配置须知 ...
- [剑指Offer]6-从尾到头打印链表
典型的后进先出,可以借助栈,也可以使用递归. 考虑到若链表过长递归可能造成函数调用栈溢出,所以使用栈更好. 注意stack无遍历操作,全部用push(),pop(),top()完成. 以下创建列表胡乱 ...