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 =============================以下是最小生成树+并 ...
随机推荐
- Android APP代码拨打电话、打开手机分享功能等隐式意图
Android APP拨打电话: Intent intent=new Intent(Intent.ACTION_DIAL,Uri.parse("tel:"+110)); start ...
- JSON-C 的安装与使用
下载源代码安装步骤 wget http://oss.metaparadigm.com/json-c/json-c-0.9.tar.gz tar xvf json-c-0.9.tar.gz cd jso ...
- Ctrl-A全选
Ctrl-A全选这点事(C#,WinForm) 所有的文本框,不管单行多行都Ctrl-A全选就好了吧?是啊,很方便.Windows的软件基本都是这样.可为什么我们自己制作的WinForm就默认不是 ...
- 使用 sphinx 制作简洁而又美观的文档
使用 sphinx 制作简洁而又美观的文档 使用 sphinx 制作简洁而又美观的文档
- poj - 1170 - Shopping Offers(减少国家dp)
意甲冠军:b(0 <= b <= 5)商品的种类,每个人都有一个标签c(1 <= c <= 999),有需要购买若干k(1 <= k <=5),有一个单价p(1 & ...
- poj3206(bfs+最小生成树)
传送门:Borg Maze 题意:有一个迷宫,里面有一些外星人,外星人用字母A表示,#表示墙,不能走,空格可以走,从S点出发,在起点S和A处可以分叉走,问找到所有的外星人的最短路径是多少? 分析:分别 ...
- hdu4705(树形dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4705 题意: 有一颗树, 选出3个点. 不在同一条路径上的集合数. 分析:这题主要能逆向思考下,用总的 ...
- 啊我V办我偶看篇未改片考i
http://pan.baidu.com/share/link?shareid=3011665141&uk=338692646&third=15 http ...
- C++ Primer 学习笔记_98_特殊的工具和技术 --优化内存分配
特殊的工具和技术 --优化内存分配 引言: C++的内存分配是一种类型化操作:new为特定类型分配内存,并在新分配的内存中构造该类型的一个对象.new表达式自己主动执行合适的构造函数来初始化每一个动态 ...
- ORA-16525: the Data Guard broker is not yet available
DGMGRL> disable configuration;ORA-16525: the Data Guard broker is not yet available Configuration ...