ZOJ 3635 Cinema in Akiba
来源:互联网 发布:php api 上传图片 编辑:程序博客网 时间:2024/06/05 16:45
Cinema in Akiba (CIA) is a small but very popular cinema in Akihabara. Every night the cinema is full of people. The layout ofCIA is very interesting, as there is only one row so that every audience can enjoy the wonderful movies without any annoyance by other audiences sitting in front of him/her.
The ticket for CIA is strange, too. There are n seats in CIA and they are numbered from 1 to n in order. Apparently, n tickets will be sold everyday. When buying a ticket, if there are k tickets left, your ticket number will be an integeri (1 ≤i ≤k), and you should choose the ith empty seat (not occupied by others) and sit down for the film.
On November, 11th, n geeks go to CIA to celebrate their anual festival. The ticket number of theith geek isai. Can you help them find out their seat numbers?
Input
The input contains multiple test cases. Process to end of file.
The first line of each case is an integer n (1 ≤ n ≤ 50000), the number of geeks as well as the number of seats inCIA. Then follows a line containingn integersa1,a2, ..., an (1 ≤ai ≤n - i + 1), as described above. The third line is an integerm (1 ≤m ≤ 3000), the number of queries, and the next line ism integers,q1,q2, ..., qm (1 ≤qi ≤n), each represents the geek's number and you should help him find his seat.
Output
For each test case, print m integers in a line, seperated by one space. Theith integer is the seat number of theqith geek.
Sample Input
31 1 131 2 352 3 3 2 152 3 4 5 1
Sample Output
1 2 34 5 3 1 2
题意:一群人到电影院看电影,该电影的门票计算比较特殊,如:甲第一个拿到1号门票则位置为1,乙第二个拿票,票号也是1,则位置为2,因为1号位置已经被甲占了,乙的位置为剩下位置中的1号位置。
思路:线段树入门,套模板。
#include<stdio.h>#include<cstdio>#define inf 55555#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1int sum[inf];int a[inf];int b[inf];int c;void build(int l,int r, int rt){ sum[rt]=r-l+1; if(l==r)return; int m=(l+r)>>1; build(lson); build(rson);}int update(int p,int l,int r,int rt){ sum[rt]--; if(l==r)return l; int m=(l+r)>>1; if(p<=sum[rt<<1]) return update(p,lson); else return update(p-sum[rt<<1],rson);}int main(){int m,i,n;while(scanf("%d",&n)!=EOF){build(1,n,1);for(i=1;i<=n;i++){scanf("%d",&c);a[i]=update(c,1,n,1);}scanf("%d",&m);for(i=1;i<=m;i++){scanf("%d",&b[i]);}for(i=1;i<m;i++)printf("%d ",a[b[i]]);printf("%d\n",a[b[m]]);}return 0;}
- ZOJ-3635-Cinema in Akiba
- ZOJ 3635 Cinema in Akiba
- zoj 3635 Cinema in Akiba
- ZOJ 3635 Cinema in Akiba[ 块状数组 ]
- ZOJ 3635 Cinema in Akiba【线段树】
- ZOJ 3635 Cinema in Akiba(树状数组 + 二分)
- Poj 2828 Buy Tickets \ Zoj 3635 Cinema in Akiba
- ZOJ 3635 Cinema in Akiba (树状数组+二分)
- zoj 3635 Cinema in Akiba(树状数组+二分)
- ZOJ 3635 Cinema in Akiba(线段树)
- ZOJ 题目3635 Cinema in Akiba(线段树插空)
- ZOJ 3635 Cinema in Akiba(二分+树状数组)
- zoj 3635 Cinema in Akiba 二分+树状数组
- ZOJ3635 Cinema in Akiba
- zoj3635 Cinema in Akiba
- ZOJ 3635——Cinema in Akiba(树状数组+二分)
- zoj 3635 Cinema in Akiba 树状数组求第K大
- ZOJ Monthly, August 2012 - C Cinema in Akiba 树状数组+二分
- 【C++ Primer 学习笔记】 chapter 10 关联容器
- CSS格式化,Meyer和YUI
- 驱动检测
- 每天问自己5个问题
- [设计模式整理笔记 五] 创建者模式(Builder)
- ZOJ 3635 Cinema in Akiba
- 一次ITL锁导致的系统问题
- HDU 2282
- jquery分页效果
- iOS开发笔记--如何自定义启动画面Default.png加载时间
- TC1.0使用方法
- [设计模式整理笔记 六] 工厂模式与创建者模式总结
- c# string两个函数的用法
- Java注释规范