标签:puts placed ges ret mis file ota cst rect
题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=2795
题目:
Time Limit: 20000/8000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 22963 Accepted Submission(s): 9513
1 #include <cstdio> 2 #include <algorithm> 3 using namespace std; 4 const int N=2e5+5; 5 int n,w,h; 6 int a[N]; 7 struct node{ 8 int l,r; 9 int MAX; 10 }tree[N*4];//只要开到8e5就可以了,布告栏的高度n以上的结果都一样 11 void build(int l,int r,int i){ 12 if(i>4*n) return ; 13 tree[i].l=l; 14 tree[i].r=r; 15 tree[i].MAX=w;//当区间的MAX小于给定的广告宽时,一定不能张贴,反之则肯定可以 16 if(l==r) return ; 17 int mid=(l+r)/2; 18 build(l, mid, 2*i); 19 build(mid+1, r, 2*i+1); 20 21 } 22 void update(int i,int x){ 23 if(tree[i].l==tree[i].r){ 24 tree[i].MAX-=x; 25 printf("%d\n",tree[i].l); 26 return ; 27 } 28 if(tree[2*i].MAX>=x) update(2*i, x); 29 else if(tree[2*i+1].MAX>=x) update(2*i+1, x); 30 tree[i].MAX=max(tree[2*i].MAX, tree[2*i+1].MAX); 31 } 32 int main(){ 33 while(scanf("%d%d%d",&h,&w,&n)!=EOF){ 34 for (int i=0; i<n; i++) scanf("%d",&a[i]); 35 build(1, min(h,n), 1);//注意树的区间只要开到min(h,n)即可 36 for (int i=0; i<n; i++) { 37 if(tree[1].MAX>=a[i]) update(1, a[i]); 38 else printf("-1\n"); 39 } 40 } 41 return 0; 42 }
标签:puts placed ges ret mis file ota cst rect
原文地址:http://www.cnblogs.com/uniles/p/7193545.html