门户:

problemCode=3635">ZOJ 3635

Cinema in Akiba


Time Limit: 3 Seconds     
Memory Limit: 65536 KB


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 ≤
ik), 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 is
ai. 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 containing
n integers a1,a2, ...,
an
(1 ≤ ain - 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 ≤
qin), 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 the
qith geek.

Sample Input

3
1 1 1
3
1 2 3
5
2 3 3 2 1
5
2 3 4 5 1

Sample Output

1 2 3
4 5 3 1 2

思路:链表模拟一排座位1-n,不断删除,然后记录座位号。用普通的链表模拟。必定TLE。so上块状链表。来弥补链表索引太慢的缺点。

代码:

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
#include<climits>
#define INF INT_MAX
using namespace std; struct node{
int num[1000];
int sz;
node* next;
node(int sz){
this->sz=sz;
next=0;
}
}*head=NULL; int local[50010];
node *get_pos(int &x)
{
node *t=head->next;
while(t->next&&x>t->sz)
{
x-=t->sz;
t=t->next;
}
return t;
} void del(node *pos,int x,int ii)
{
local[ii]=(pos->num)[x-1];
for(int i=x;i<pos->sz;i++)
(pos->num)[i-1]=(pos->num)[i];
(pos->sz)--;
} void build_bl(int n)
{
node *ret=head;
int sz=ceil(sqrt(n));
int cur=0;
for(int i=0;i<n/sz;i++)
{
node *t=new node(sz);
for(int j=0;j<sz;j++)
(t->num)[j]=(++cur); ret->next=t;
ret=t;
} if(n%sz)
{
node *t=new node(n%sz);
for(int i=0;i<n%sz;i++)
(t->num)[i]=(++cur);
ret->next=t;
}
} void free_head()
{
node *p=head;
while(head->next)
{
head=head->next;
free(p);
p=head;
}
} int main()
{
int n,m;
while(scanf("%d",&n)!=EOF)
{
head=new node(0);
build_bl(n);
for(int i=1;i<=n;i++)
{
//printf("__hear\n");
int x;
scanf("%d",&x);
node *pos=get_pos(x);
del(pos,x,i);
}
free_head();
scanf("%d",&m);
int q;
scanf("%d",&q);
printf("%d",local[q]);
for(int i=1;i<m;i++)
{
scanf("%d",&q);
printf(" %d",local[q]);
}
printf("\n");
}
return 0;
}

版权声明:欢迎follow我的开源项目:https://github.com/skyqinsc

ZOJ 3635 Cinema in Akiba[ 大规模阵列 ]的更多相关文章

  1. ZOJ 3635 Cinema in Akiba(线段树)

    Cinema in Akiba (CIA) is a small but very popular cinema in Akihabara. Every night the cinema is ful ...

  2. ZOJ 3635 Cinema in Akiba (第一次组队) 树状数组+二分

    Cinema in Akiba Time Limit: 3 Seconds      Memory Limit: 65536 KB Cinema in Akiba (CIA) is a small b ...

  3. ZOJ - 3635 Cinema in Akiba(树状数组+二分)

    题意:已知有n个人,从第一个人开始每个人被安排在第ai个空座上,有m组询问,问某人所坐的位置. 分析: 1.用树状数组维护空座的个数,方法: 将所有的空座初始化为1,sum(x)则表示从座位1到座位x ...

  4. 毫米波大规模阵列中的AOA估计

    1.AOA估计在毫米波大规模MIMO中的重要性 在毫米波大规模MIMO的CSI估计中,AoA估计具有重要地位,主要原因归纳如下: 毫米波大规模MIMO 的信道具有空域稀疏性,可以简单通过AoA 和路径 ...

  5. uva 12003 Array Transformer (大规模阵列)

    白皮书393页面. 乱搞了原始数组中.其实用另一种阵列块记录. 你不能改变原始数组. 请注意,与原来的阵列和阵列块的良好关系,稍微细心处理边境.这是不难. #include <cstdio> ...

  6. 【电子电路技术】短波红外InGaAs探测器简析

    核心提示: 红外线是波长介于微波与可见光之间的电磁波,波长在0.75-1000μm之间,其在军事.通讯.探测.医疗等方面有广泛的应用.目前对红外线的分类还没有统一的标准,各个专业根据应用的需要,有着自 ...

  7. ZOJ Problem Set - 3635

    题目大意 有n个从1..n标号的座位,按时间顺序给出每个客人来的时候是坐在第几个空座位,最后给若干个询问问第i号客人坐在哪里 分析 线段树+二分 // Fast Sequence Operations ...

  8. 小小知识点(二十五)5G关键技术——Massive MIMO(大规模天线阵列)和beamforming(波束成形)

    转自http://www.elecfans.com/d/949864.html 多输入多输出技术(Multiple-Input Multiple-Output,MIMO)是指在发射端和接收端分别使用多 ...

  9. 【转载】图论 500题——主要为hdu/poj/zoj

    转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...

随机推荐

  1. OpenRisc-32-ORPSoC烧写外部spi flash

    引言 经过前面的分析和介绍,我们对ORPSoC的启动过程(http://blog.csdn.net/rill_zhen/article/details/8855743)和 ORpSoC的debug子系 ...

  2. 使用模板类导致error LNK2019: 无法解析的外部符号

    原地址 1.定义模板类: template<class T> class Stack {....}; 2.定义模板成员函数: 每个函数头都要以相同的模板声明打头,并将类限定符改成:类名&l ...

  3. Spark实践的阶段性总结

    写这篇小总结是因为前段时间是自己业余时间对Spark相关进行了些探索,接下来可能有别的同事一起加入,且会去借用一些别的服务器资源,希望可以借此理下思路. 实践Spark的原因 在之前Spark简介及安 ...

  4. LeetCode——Search in Rotated Sorted Array II

    Follow up for "Search in Rotated Sorted Array": What if duplicates are allowed? Would this ...

  5. Object.wait()的使用方法示例(转)

    本文节选自 Effective Java by Joshua Bloch 和 Concurrent Programming in Java by Doug Lea. 1.3 原子数据的同步 java语 ...

  6. hdu5001(概率dp)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=5001 题意:一个人随即从一个点出发,到达邻接点的概率相同,求出走d步都不会到达1~n点的每一点i的概率 ...

  7. 实习第一天之数据绑定:<%#Eval("PartyName")%>'

    1.asp:HyperLink ID="Link" runat="server" Target="_blank" Text='<%#E ...

  8. H3C低端交换机MAC绑定

    1.MAC地址和端口的绑定<h3c>system[h3c]interface e0/1[h3c-interface]mac-address max-count #关闭交换机端口的MAC学习 ...

  9. hibernate得知——Set设置配置

    Set设置配置 创建数据表:表关系的员工有多重身份 create table EMPLOYEE ( id INT NOT NULL auto_increment, first_name VARCHAR ...

  10. EF一次请求公用一个实例

    应用场景: 我们在程序开发时,对数据库的操作是必不可少的部分,常规的做法是直接使用Using()语句块,在用完后立即释放连接资源,这种做法在桌面应用程序中毫无问题,但是在Web程序中,尤其是在当今大数 ...