HDU 2795 线段树 水题
来源:互联网 发布:林非比淘宝模特 编辑:程序博客网 时间:2024/06/14 15:19
水题
从左至右找到位置就插入即可
#include "stdio.h"
#include "string.h"
#include "math.h"
#include "stdlib.h"
#include "algorithm"
#include "iostream"
using namespace std;
int w;
struct comp
{
int l,r,mid,max;
} data[600010];
int max(int a,int b)
{
if (a<b) return b;
else return a;
}
void build(int l,int r,int k)
{
data[k].l=l;
data[k].r=r;
data[k].mid=(l+r)/2;
data[k].max=w;
if (l==r) return ;
build(l,data[k].mid,k*2);
build(data[k].mid+1,r,k*2+1);
}
void search(int x,int k)
{
if (data[k].l==data[k].r)
{
printf("%d\n",data[k].l);
data[k].max-=x;
return ;
}
if (data[k*2].max>=x) search(x,k*2);
else
search(x,k*2+1);
data[k].max=max(data[k*2].max,data[k*2+1].max);
}
int main()
{
int h,n,x,m;
while (scanf("%d%d%d",&h,&w,&n)!=EOF)
{
if (h<n) m=h; else m=n; // 缩小树的范围
build(1,m,1);
while (n--)
{
scanf("%d",&x);
if (data[1].max<x) printf("-1\n");
else search(x,1);
}
}
return 0;
}
- HDU 2795 线段树 水题
- hdu 2795 线段树
- hdu~2795~线段树
- hdu 2795线段树
- hdu 2795 线段树
- HDU 2795 线段树
- hdu 2795 线段树
- hdu~2795(线段树)
- HDU 2795 线段树
- hdu 2795 线段树
- hdu 2795(线段树)
- hdu 2795(线段树)
- hdu 2795 线段树
- HDU 2795 线段树
- HDU 2795 线段树
- HDU 2795 Billboard线段树
- HDU 2795 Billboard 线段树
- Billboard HDU 2795 线段树
- 设备驱动程序学习笔记(1)
- Ext学习笔记(6):FormPanel 的Demo
- 【作业解答】第一次上机样例程序
- Life of an instruction in LLVM
- 大数据相关
- HDU 2795 线段树 水题
- 海量数据处理汇总
- 几点iOS开发技巧
- 数据结构与程序设计 练习3.3 E7
- mac环境下使用vi进行文本换行
- jsp 用表格显示出jdbc查询出的数据
- 指针的用法
- hdu1845 Jimmy’s Assignment (最大匹配Hopcroft-Karp算法)
- 为什么匿名内部类参数必须为final类型