线段树-HDU2795Billboard
来源:互联网 发布:php字符串替换 第一个 编辑:程序博客网 时间:2024/05/16 18:25
题目大意:给个h*w的告示板 每次贴告示(1*w)都要尽量往高 和 左边贴 求每个告示贴上去的高度
这个代码我真不好意思贴··· 扒的 勿怪··· 谁叫我是靠模板生存的渣呢···
原帖地址
http://www.notonlysuccess.com/index.php/segment-tree-complete/
#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#include <algorithm>#define ll long long#define eps 1e-8#define ms(x,y) (memset(x,y,sizeof(x)))#define fr(i,x,y) for(int i=x;i<=y;i++)using namespace std;/*线段树 点修改 区间最大值*/#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1const int maxn=200000+10;int tree[maxn<<2];int h,w,n;void pushup(int rt){ tree[rt]=max(tree[rt<<1],tree[rt<<1|1]);}void build(int l,int r,int rt){ tree[rt]=w; if(l==r)return ; int m=(l+r)>>1; build(lson); build(rson); pushup(rt);}int query(int x,int l,int r,int rt){ if(l==r) { tree[rt]-=x; return l; } int m=(l+r)>>1; int ret=(tree[rt<<1]>=x)?query(x,lson):query(x,rson); pushup(rt); return ret;}/*end-线段树 点修改 区间最大值*/void init(){ h=min(h,n); build(1,h,1);}void doit(){ fr(i,1,n) { int x; scanf("%d",&x); if(tree[1]<x)printf("-1\n"); else printf("%d\n",query(x,1,h,1)); }}int main(){ while(~scanf("%d%d%d",&h,&w,&n)) { init(); doit(); } return 0;}
0 0
- hdu2795Billboard(线段树)
- 线段树-HDU2795Billboard
- hdu2795Billboard 线段树
- hdu2795Billboard【线段树】
- hdu2795Billboard(线段树)
- HDU2795Billboard (线段树)
- HDU2795Billboard--线段树单点更新
- hdu2795Billboard (线段树,看作点更新)
- hdu2795Billboard(线段树,找第一个大于w的点)
- HDU2795Billboard
- hdu2795Billboard
- hdu2795Billboard
- hdu2795Billboard
- hdu2795Billboard
- HDU2795Billboard
- 线段树?线段树!
- 线段树?线段树!
- 线段_线段树
- mysql服务性能优化—my.cnf配置说明详解
- YUV格式转换为RGB(基于opencv)
- WinSock客户端和服务端(select模型)
- tomcat 参数调优--maxThreads、acceptCount(最大线程数、最大排队数)
- Windows live writer 编辑 Orchard
- 线段树-HDU2795Billboard
- 会大幅度法国红酒电工个好更大的个发的深深地
- DynamicJasper创建动态报表
- 火锅减肥杜是风格的收费更好个回复个好复古刚好是冬天
- java web学习笔记--Eclipse的常见操作
- UML类图符号 各种关系说明以及举例
- 腾讯、优酷视频地址解析(转)
- hdu 1796 How many integers can you find (容斥原理)
- Cython的学习方法