门户:

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. 各种oracle10g下载地址(官网网页上好像找不到了)

    Oracle Database 10g Release 2 (10.2.0.1.0) Enterprise/Standard Edition for Microsoft Windows (32-bit ...

  2. cocos2d-x开关按钮类CCControlSwitch

    在test项目中的ControlExtensionText\ CCControlSwitchTest目录下面的CCControlSwitchTest.cpp中,通过这个例子,我们也可以制作出不错的开关 ...

  3. HDSF主要节点解说(二)工作原理

    HDFS(Hadoop Distributed File System )Hadoop分布式文件系统. 是依据google发表的论文翻版的.论文为GFS(Google File System)Goog ...

  4. struts2第一个程序的详解(配图)

    首先我们在struts2中要写上一个action <packagename="fish"namespace="/test"extends="st ...

  5. Python数据结构-字典

    tel={,} tel[ print(tel) print(tel['tom']) del tel['tom'] print(tel) print(tel.keys()) 运行结果: {, , } { ...

  6. 京东商城招聘scala 高级开发工程师 T3级别

    岗位级别:T3 岗位职责: 1.参与自动调价.匹配系统的设计和实现 岗位要求: 1. 一年以上scala开发经验2.良好的函数式编程能力3. JAVA基础扎实4.熟悉大数据处理,有hadoop/hba ...

  7. UVA12304 2D Geometry 110 in 1! 计算几何

    计算几何: 堆几何模版就能够了. . .. Description Problem E 2D Geometry 110 in 1! This is a collection of 110 (in bi ...

  8. vb.net版机房收费——助你学会七层架构(一)

    我自己写机房的时候,看非常多高人的博客,各种的借鉴,当初务必的纠结,如今整个机房敲完了,写这篇博客给大家一个总体上的.简单理解的七层,期望大家看完这篇文章之后,不会这个纠结了. 首先大家得看了我的上一 ...

  9. IOS开发应用

    IOS开发应用 我的第一个IOS开发应用 1. 需求描述 2. 开发环境介绍 3. 创建一个工程 4. 工程配置介绍 5. 目录结构介绍 6. 界面设置 7. 关联输入输出 8. 关联事件代码 9.  ...

  10. 【转载】SQL Server 2008 中新建用户登录并指定该用户的数据库

    提要:我在 SQL Server 中新建用户登录时,出现了三种错误,错误代码分别是 18456.15128.4064 -----------------------------------  正 文 ...