poj Hotel 线段树】的更多相关文章

经典线段树的题. 每个节点存储的信息:左端点连续空房间的长度,右端点连续空房间长度,连续空房间的最大长度. 由于要求每次必须从尽量靠左边的位置进行居住,那么搜索时应尽量让区间起始位置更小: 1.如果当前区间的最大空房间长度小于要寻找的长度,说明不会找到符合的区间,直接退出. 2.如果左子区间的最大空房间长度大于等于要寻找的长度,那么应该进入左子区间查找. 3.否则,如果左子区间的右端点连续空房间长度 + 右子区间的左端点连续空房间的长度 大于等于 要寻找的长度则直接返回左子区间右端点起始空房间下…
Who Gets the Most Candies? Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 12744   Accepted: 3968 Case Time Limit: 2000MS Description N children are sitting in a circle to play a game. The children are numbered from 1 to N in clockwise…
[USACO08FEB]酒店Hotel 线段树 题面 其实就是区间多维护一个lmax,rmax(表示从左开始有连续lmax个空房,一直有连续rmax个空房到最右边),合并时讨论一下即可. void push_up(int x, int l, int r){ int mid=(l+r)>>1; if(sum[lson]==mid-l+1) lmax[x]=sum[lson]+lmax[rson]; else lmax[x]=lmax[lson]; if(sum[rson]==r-(mid+1)+…
http://poj.org/problem?id=3667 Hotel Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 9484   Accepted: 4066 Description The cows are journeying north to Thunder Bay in Canada to gain cultural enrichment and enjoy a vacation on the sunny s…
Hotel 转载自:http://www.cnblogs.com/scau20110726/archive/2013/05/07/3065418.html [题目链接]Hotel [题目类型]线段树 区间合并 &题意: 有一个线段,从1到n,下面m个操作,操作分两个类型,以1开头的是查询操作,以2开头的是更新操作 1 w 表示在总区间内查询一个长度为w的可用区间,并且要最靠左,能找到的话返回这个区间的左端点并占用了这个区间,找不到返回0 好像n=10 , 1 3 查到的最左的长度为3的可用区间就…
题目链接 线段树的区间合并. 和上一题差不多....第三种操作只需要输出maxx[1]的值就可以. #include <iostream> #include <vector> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <map> #include <set> #include <s…
http://poj.org/problem?id=3468 题意:给n个数字,从A1 …………An m次命令,Q是查询,查询a到b的区间和,c是更新,从a到b每个值都增加x.思路:这是一个很明显的线段树的题目,就是线段树的用区间更新就可以,我也是第一次用.. #include <stdio.h> #include <string.h> #define maxn 100050 long long arra[ maxn ]; struct note{ //要用long long 类型…
题目: 输入两个数(m,n),m表示牛的头数,n表示查询的个数.查询时输入两个数(x,y),表示查询范围的起始值和终止值,查询结果是,这个区间内牛重量的最大值减去牛重量的最小值,数量级为1000,000 设计每次查询的复杂度为logm. 例如, 输入: 6 3 1 7 3 4 2 5 1 5 4 6 2 2 输出: 6 3 0     分析:这道题是典型的空间换时间的题.一看到是区间的查找,我们应该想到线段树,这里有一篇我觉得写得挺好的介绍线段树的博客和大家分享一下:http://www.cnb…
Buy Tickets Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 15422   Accepted: 7684 Description Railway tickets were difficult to buy around the Lunar New Year in China, so we must get up early and join a long queue… The Lunar New Year wa…
Hotel The cows are journeying north to Thunder Bay in Canada to gain cultural enrichment and enjoy a vacation on the sunny shores of Lake Superior. Bessie, ever the competent travel agent, has named the Bullmoose Hotel on famed Cumberland Street as t…