门户:

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. Merging a WPF application into a single EXE(WPF应用程序合并成单个Exe文件)

    I always dislike handing off little applications to people. Not because I can’t, but because of the ...

  2. hdu1025(nlon(n)最长上升子序列)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1025 大致思路:设置两个a,b数组,a数组存储数据,b数组存储最长不降序序列.此算法关键在于设计二分查 ...

  3. 约瑟夫问题--list模拟循环链表

    约瑟夫问题 Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描写叙述 n个人想玩残酷的死亡游戏,游戏规则例如以下: n个人进行编号,分别 ...

  4. Spring IOC及AOP学习总结

    一.Spring IOC体系学习总结: Spring中有两个容器体系,一类是BeanFactory.还有一类是ApplicationContext.BeanFactory提供了基础的容器功能.Appl ...

  5. HDU 5066 Harry And Physical Teacher(物理题)

    HDU 5066 Harry And Physical Teacher 思路:利用物理里面的动量守恒公式.因为保证小车质量远大于小球.所以能够把小车质量当成无穷大带进去,得到答案为2 * v0 - v ...

  6. JPush极光推送 Java调用服务器端API开发

       极光推送是:使得开发者可以即时地向其应用程序的用户推送通知或者消息,与用户保持互动,从而有效地提高留存率,提升用户体验.简单的说就是通过JPush后台管理网站进行app消息的推送.可以让用户及时 ...

  7. 09_android入门_採用android-async-http开源项目的GET方式或POST方式实现登陆案例

    依据08_android入门_android-async-http开源项目介绍及用法的介绍,我们通过最常见的登陆案例进行介绍android-async-http开源项目中有关类的使用.希望对你学习an ...

  8. Linux C语言写的超级简单port扫描器

    这个本来曾经也写过的,今天无聊复习下 再写一遍.简单的一塌糊涂,写的不咋地大家见谅哦!有空再加强 嘿嘿! #include <stdio.h> #include <stdlib.h& ...

  9. html 跳转页面,同时跳转到一个指定的位置

    比如我现在 a.html 的时候,我想跳转到 b.html ,并且是 b.html 的某一个位置,用 <a href=>, a.html里: <a href="b.html ...

  10. cocos2dx移植android平台

    本人这几天一直都没有跟新自己的网站内容,问我干什么去了,当然是做这篇文章做的事了,说起这个移植来真是麻烦啊,网上试验了各种方法,都不知道谁对谁错啊.不过经过本人这三天的研究最后终于成功了,为了让大家少 ...