HDU - 2795 Billboard
来源:互联网 发布:超鲸营销 seo常用工具 编辑:程序博客网 时间:2024/06/03 19:36
1.题面
http://acm.hdu.edu.cn/showproblem.php?pid=2795
2.题意
我觉得中文题不需要解释题面.
3.思路
将这块宣传板以h为边建线段树,对于每次的输入tmp,只要将最左端的大于tmp的值减tmp就好了,
因为没有注意到n可以等于1,所以错了一次.
没有注意到l和r是可以在查询的过程中传递下去的,浪费了很多空间.
4.代码
/***************************************************************** > File Name: Cpp_Acm.cpp > Author: Uncle_Sugar > Mail: uncle_sugar@qq.com > Created Time: 2016年05月12日 星期四 18时23分50秒*****************************************************************/# include <cstdio># include <cstring># include <cctype># include <cmath># include <cstdlib># include <climits># include <iostream># include <iomanip># include <set># include <map># include <vector># include <stack># include <queue># include <algorithm>using namespace std;const int debug = 1;const int size = 200000 + 10; const int INF = INT_MAX>>1;typedef long long ll;struct node{intmax;int l,r;node(){}}segtree[4*size];int h,w,n;void build(int n, int l, int r){segtree[n].l = l;segtree[n].r = r;if (l==r)segtree[n].max = w;else {int mid = (l+r)>>1;int lc = n<<1;int rc = n<<1|1;build(lc,l,mid);build(rc,mid+1,r);segtree[n].max = max(segtree[lc].max,segtree[rc].max);}}int query_set(int n,int k){if (segtree[n].l==segtree[n].r){segtree[n].max -= k;return segtree[n].l;}int lc = n<<1;int rc = n<<1|1;int ret = -1;if (segtree[lc].max >= k){ret = query_set(lc,k);}else if (segtree[rc].max >= k){ret = query_set(rc,k);}segtree[n].max = max(segtree[lc].max,segtree[rc].max);return ret;}int main(){std::ios::sync_with_stdio(false);cin.tie(0);int i,j,tmp;while (cin >> h >> w >> n){build(1,1,min(h,n));for (i=0;i<n;i++){cin >> tmp;cout << (segtree[1].max>=tmp?query_set(1,tmp):-1) << endl;}}return 0;}
0 0
- hdu 2795 Billboard
- hdu 2795 Billboard
- hdu 2795 Billboard
- hdu 2795 Billboard
- hdu 2795 Billboard
- hdu 2795 Billboard
- HDU 2795 - Billboard
- hdu 2795 Billboard
- HDU-2795-Billboard
- HDU 2795 Billboard
- hdu 2795 Billboard
- HDU 2795 Billboard
- hdu 2795 Billboard
- Hdu 2795 Billboard
- Hdu 2795 Billboard
- hdu 2795 Billboard
- hdu 2795 Billboard
- hdu 2795 Billboard
- UI 增加热点区域
- ExpandableListView的使用
- Permisson Denied !ssh传输文件报错
- mysql 多表 update sql语句总结
- VS2013 配置 VLFeat
- HDU - 2795 Billboard
- 计算机图像分析、计算机视觉会议日历 日期备忘录Calendar of Computer Image Analysis, Computer Vision Conferences
- 中标桌面系统使用
- POJ 3468 A Simple Problem with Integers 线段树 区间修改
- 代码块
- IOS-sql语句中遇到的字符串拼接
- 类别、延展、委托代理(16.5.12)
- docker php-fpm nginx 配置
- service的几种启动模式(交互)