HDU 2795 Billboard
来源:互联网 发布:mac桌面贴便签 编辑:程序博客网 时间:2024/05/18 21:05
题意:
海报按顺序贴在,可以贴的最左上方。
题解:
最多有min(h,n)行可以贴,那么,每行看成一个节点,用线段树去维护。
//HDU 2795 Billboard#include<stdio.h>#include<math.h>#include<algorithm>using namespace std;#define MAX 200009*3struct Node { int Max; int L,R; Node *left; Node *right;};Node Tree[MAX];int ans,w,cnt;void build(int l,int r,struct Node *root) { root->Max=w; root->L=l; root->R=r; if(l==r) return; int mid=(l+r)/2; cnt++; root->left=Tree+cnt; cnt++; root->right=Tree+cnt; build(l,mid,root->left); build(mid+1,r,root->right);}void query(int len,struct Node *root) { if(root->Max<len) return; if(root->L==root->R) { root->Max-=len; ans=root->L; return ; } if(root->left->Max>=len) { query(len,root->left); } else { query(len,root->right); } root->Max=max(root->left->Max,root->right->Max);}int main() { int n,h; while(~scanf("%d %d %d",&h,&w,&n)) { cnt=0; int tmp=min(h,n); build(1,tmp,Tree); for(int i=0; i<n; i++) { scanf("%d",&tmp); ans=-1; query(tmp,Tree); printf("%d\n",ans); } } 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
- [poj1144 Network]tarjan求割点
- 大话工厂三剑客
- iOS--UITableView Grouped样式详细代码
- view的setTag() 和 getTag()应用
- 认真做人,努力做事情,我就是这样的程序员
- HDU 2795 Billboard
- 保留两位小数
- Adapter的含意,及用法
- C语言,指针变量的*p,p以及&p的区别
- 碰撞球小游戏开发总结
- 超级马里奥强势来袭
- iOS--UIViewController生命周期
- 【0Day】栈溢出漏洞基础——简单输入漏洞 & 修改返回函数
- iOS--UIScrollView和UIPageControl配合使用完成引用介绍页面