poj 2828 Buy Ticket
来源:互联网 发布:车辆仿真设计软件 编辑:程序博客网 时间:2024/06/08 14:19
从最后一个数开始考虑,比较空位
#include <iostream>
#include <stdio.h>#include <string.h>
#include <cmath>
#include <algorithm>
using namespace std;
#define N 200200
int n[N];
struct tree
{
int l,r,sum;
}tr[4*N];
void build(int i,int l,int r)
{
tr[i].l=l;
tr[i].r=r;
tr[i].sum=r-l+1;
if(l==r)
return;
int mid=(l+r)/2;
build(i*2,l,mid);
build(i*2+1,mid+1,r);
}
int di;
void update(int i,int pos,int l,int r)
{
int mid=(l+r)/2;
tr[i].sum--;
if(l==r)
{
di=l;
return;
}
if(pos<=tr[i*2].sum)
update(i*2,pos,l,mid);
else
{
pos=pos-tr[i*2].sum;
update(i*2+1,pos,mid+1,r);
}
}
int main()
{
int t,i,a[N],p[N];
while(scanf("%d",&t)!=-1)
{for(i=1;i<=t;i++)
scanf("%d%d",&a[i],&n[i]);
build(1,1,t);
for(i=t;i>=1;i--)
{
update(1,a[i]+1,1,t);
p[di]=n[i];
}
printf("%d",p[1]);
for(i=2;i<=t;i++)
printf("% d",p[i]);
printf("\n");
}
return 0;
}
0 0
- poj 2828 Buy Ticket
- 2828Buy ticket
- hdoj Buy the Ticket
- HDU Buy the Ticket
- Buy the Ticket
- Buy the Ticket
- 1133-Buy the Ticket
- HDU1133 Buy the Ticket
- Buy the Ticket
- Buy the Ticket
- Buy the Ticket
- Buy the Ticket HDU
- Buy the Ticket
- Buy the Ticket
- HDU Buy the Ticket
- HDOJ_ 1133 Buy the Ticket
- HDOJ_ 1133 Buy the Ticket
- hdu 1133 Buy the Ticket
- 显示图像
- 问题:powerdesigner 打开没有响应,一直卡住
- java中的克隆问题
- ROS下安装和运行SVO数据包和实时详细过程
- Web初学-Web应用细节
- poj 2828 Buy Ticket
- java开发的简易学生成绩管理系统
- 测试
- android五个布局
- 一天学习记录
- 使用GridView显示图片
- 使用ProgressBar实现进度条
- android加入图片命名规则
- TensorFlow文档索引