ZOJ 3635 Cinema in Akiba[ 大规模阵列 ]
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 ≤
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 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 ≤ 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 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[ 大规模阵列 ]的更多相关文章
- ZOJ 3635 Cinema in Akiba(线段树)
Cinema in Akiba (CIA) is a small but very popular cinema in Akihabara. Every night the cinema is ful ...
- ZOJ 3635 Cinema in Akiba (第一次组队) 树状数组+二分
Cinema in Akiba Time Limit: 3 Seconds Memory Limit: 65536 KB Cinema in Akiba (CIA) is a small b ...
- ZOJ - 3635 Cinema in Akiba(树状数组+二分)
题意:已知有n个人,从第一个人开始每个人被安排在第ai个空座上,有m组询问,问某人所坐的位置. 分析: 1.用树状数组维护空座的个数,方法: 将所有的空座初始化为1,sum(x)则表示从座位1到座位x ...
- 毫米波大规模阵列中的AOA估计
1.AOA估计在毫米波大规模MIMO中的重要性 在毫米波大规模MIMO的CSI估计中,AoA估计具有重要地位,主要原因归纳如下: 毫米波大规模MIMO 的信道具有空域稀疏性,可以简单通过AoA 和路径 ...
- uva 12003 Array Transformer (大规模阵列)
白皮书393页面. 乱搞了原始数组中.其实用另一种阵列块记录. 你不能改变原始数组. 请注意,与原来的阵列和阵列块的良好关系,稍微细心处理边境.这是不难. #include <cstdio> ...
- 【电子电路技术】短波红外InGaAs探测器简析
核心提示: 红外线是波长介于微波与可见光之间的电磁波,波长在0.75-1000μm之间,其在军事.通讯.探测.医疗等方面有广泛的应用.目前对红外线的分类还没有统一的标准,各个专业根据应用的需要,有着自 ...
- ZOJ Problem Set - 3635
题目大意 有n个从1..n标号的座位,按时间顺序给出每个客人来的时候是坐在第几个空座位,最后给若干个询问问第i号客人坐在哪里 分析 线段树+二分 // Fast Sequence Operations ...
- 小小知识点(二十五)5G关键技术——Massive MIMO(大规模天线阵列)和beamforming(波束成形)
转自http://www.elecfans.com/d/949864.html 多输入多输出技术(Multiple-Input Multiple-Output,MIMO)是指在发射端和接收端分别使用多 ...
- 【转载】图论 500题——主要为hdu/poj/zoj
转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...
随机推荐
- PHP开发学习门户改版效果图投票
亲们,PHP开发学习门户上线两个月啦,站长想进行一次改版.希望大家在留下宝贵的一票.选出喜欢的样式吧 A样式: B样式: mod=misc&action=votepoll&fid=46 ...
- zoj2760(最大流)
传送门:How Many Shortest Path 题意:给出n个点,和n*n的矩阵表示有向图.a[i][j]为-1表示i到j没有路径:不为-1则表示i到j的路径长度.给出一个vs和vt,要求vs到 ...
- 跟我extjs5(38--单个模块的设计[6获得模块列表数据])
跟我extjs5(38--单个模块的设计[6获得模块列表数据]) 在程序的前一个表以及,据的执行过程. 在菜单中选择 "系统管理"--"模块分组" ...
- Window8.1 64位无法使用Debug命令的解决方法[附牛人代码]
偶然看到网上一篇文章,讲的是世界黑客编程大赛第一名的一个很酷的程序,大小仅有4KB,使用debug命令执行. 悲催的是win8.1的debug命令不能使用. 错误例如以下: 解决方法例如以下: 1. ...
- CCLuaObjcBridge调Objective-C方法传索引数组报invalid key to 'next'错调试
CCLuaObjcBridge是cocos2d-x系列引擎与Objective-C进行交互的"桥梁",老廖的quick-cocos2d-x在其framework进行了简单了封装,封 ...
- EF 打造冲不掉的标签
应用场景: 在用EF的Datebase Fitst模式开发时,实体都是有T4文件根据数据库来生成,并且是每次保存都会重新生成,如果我们在有T4生成的实体类上加上验证标签,那么以保存就会丢失, 解决方案 ...
- prepareCall()运行存储过程
CallableStatement 对象为全部的 DBMS 提供了一种以标准形式调用已储存过程的方法.已储存过程储存在数据库中.对已储存过程的调用是 CallableStatement对象所含的内容. ...
- 强势围观,CSDN代码引用bug
看我写的一篇blog http://blog.csdn.net/laijieyao/article/details/41014355,在代码上引用了微软雅黑的字体,结果代码显示出来把我给惊呆了 竟然 ...
- Json与Java对象互转之Gson学习
Json与Java对象互转之Gson学习 请尊重他人的劳动成果.转载请注明出处:Json与Java对象互转之Gson学习 我曾在<XML,Object,Json转换之浅析Xstr ...
- 算法8-4:Kruskal算法
Kruskal算法用于计算一个图的最小生成树.这个算法的过程例如以下: 依照边的权重从小到达进行排序 依次将每条边添加到最小生成树中,除非这条边会造成回路 实现思路 第一个步骤须要对边进行排序,排序方 ...