门户: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. ZOJ3635 Cinema in Akiba(线段树)

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

  2. ZOJ3635 Cinema in Akiba

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3635 题意:有n个geek,每个人一张票,每个票号ai表示这个geek要坐 ...

  3. 浙大月赛C题(2012/8)Cinema in Akiba(线段树)

    http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=4791 (1)第一次写浙大的题目,这题让我十分意外,基本的线段树类 ...

  4. 爬取html数据中文乱码,解决PHP中file_get_contents抓取网页中文乱码问题

    根据网上有朋友介绍说原因可能是服务器开了GZIP压缩. 下面是用firebug查看我的博客的头信息,Gzip是开了的. 请求头信息原始头信息 代码如下 复制代码 Accept text/html,ap ...

  5. 5G毫米波有源阵列封装天线技术研究

    提出了一种5G 毫米波有源阵列封装天线.该阵列由8×16 个微带天线单元组成,通过耦合式差分馈电,天线实现了宽带匹配和方向图高度对称特性.通过对天线与芯片进行合理布局,减小了芯片射频端口到天线子阵的馈 ...

  6. ZOJ Monthly, August 2012 题解

    A: 题目链接:点击打开链接 Alice's present #include <cstdio> #include <iostream> #include <cstrin ...

  7. ZOJ Monthly, August 2012

    http://acm.zju.edu.cn/onlinejudge/showContestProblems.do?contestId=340 A Alice's present   题意:给出一个10 ...

  8. 【电信学】【2015】大规模MIMO:基础与系统设计

    本文为瑞典林雪平大学(作者:Hien Quoc Ngo)的毕业论文,共67页. 在过去的数十年中,连接的无线设备数量有了巨大的增长.数以十亿计的设备通过无线网络进行连接和管理.同时,每个设备都需要高吞 ...

  9. 华为5G英国首秀,BBC主持人震惊了!到底网速有多快?

    当地时间5月30日,英国电信运营商EE携手华为,正式开启英国首个商用5G信号. 据了解,本次5G商用发布覆盖英国六大城市(包括伦敦.加的夫.爱丁堡.曼彻斯特.伯明翰.贝尔法斯特),约有45万名EE用户 ...

最新文章

  1. 在MATPLOTLIB中加入汉字显示
  2. Python学习--最完整的基础知识大全
  3. typescript安装、数据类型及tsconfig配置项说明
  4. Java的二十三种设计模式(单例模式、工厂方法模式、抽象工厂模式)
  5. java设置字体大小和颜色_Java 设置Excel图表背景填充(颜色、图片填充)
  6. struct、union、enum and sizeof
  7. 富士施乐打印机双面打印设置方法
  8. cknife连接失败
  9. Vijos OJ搭建
  10. win10 下 acdsee7 在普通账户下无法运行并崩溃的 BUG
  11. 小心!第三方支付最常遇到的 6 大骗局!
  12. Java JNI调用kaldi动态链接库(Linux版本)
  13. NOIP201508跳石头
  14. php+xls加密,POI Excel xlsx加密
  15. php中的 notice,PHP中出现Notice: Undefined index的三种解决办法
  16. Day29 PythonWeb全栈课程课堂内容
  17. C++ 宽、窄字符转换
  18. 几款JVM图形化监控工具
  19. 马云退休后首次演讲!听众是全球1500名校长
  20. mpmath.psi python_Mol Cell Proteomics. |马臻| psims-一个用于编写HUPO-PSI标准下的mzML和mzIdentML的python库...

热门文章

  1. ES6新特性_ES6生成器函数实例---JavaScript_ECMAScript_ES6-ES11新特性工作笔记022
  2. STM32工作笔记0050---端口复用和重映射
  3. springCloud工作笔记090---SpringCloud_redis配置多数据源_redis多数据源
  4. C#.Net工作笔记008---c# 日期时间大小比较_日期相减
  5. C#.Net工作笔记006---关于各种四舍五入_小数点保留第几位等操作_随时更新
  6. android学习笔记---50_样式与主题,给控件使用样式,给应用使用主题
  7. Java的接口及实例(转)
  8. 跟我学SpringMVC目录汇总贴、PDF下载、源码下载
  9. sqlserver2008链接服务器的使用和oracle11g客户端修改字符集
  10. php spl函数,PHP SPL标准库中的常用函数介绍