Hyperspace

Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 1023    Accepted Submission(s): 492

Problem Description
The great Mr.Smith has invented a hyperspace particle generator. The device is very powerful. The device can generate a hyperspace. In the hyperspace, particle may appear and disappear randomly. At the same time a great amount of energy was generated.
However, the device is in test phase, often in a unstable state. Mr.Smith worried that it may cause an explosion while testing it. The energy of the device is related to the maximum manhattan distance among particle.
Particles may appear and disappear any time. Mr.Smith wants to know the maxmium manhattan distance among particles when particle appears or disappears.
 
Input
The input contains several test cases, terminated by EOF.
In each case: In the first line, there are two integer q(number of particle appear and disappear event, ≤60000) and k(dimensions of the hyperspace that the hyperspace the device generated, ≤5). Then follows q lines. In each line, the first integer ‘od’ represents the event: od = 0 means this is an appear
event. Then follows k integer(with absolute value less then 4 × 107). od = 1 means this is an disappear event. Follows a integer p represents the disappeared particle appeared in the pth event.
 
Output
Each test case should contains q lines. Each line contains a integer represents the maximum manhattan distance among paticles.
 
Sample Input

  -

  -
- -
-
Sample Output
0
746
0
1456
1456
1456
0
2512
5571
8922
 
Source
 
Recommend
zhuyuanchen520   |   We have carefully selected several similar problems for you:  4822 4821 4820 4819 4818 

 
  最远曼哈顿距离 + STL库使用
  题意是已知q和n,q是请求的数量,n是平面点的维数。接下来输入q行请求,每行请求由2部分组成,分别是指令od和操作数,od=0代表加入点,od1代表删除点。如果od=0,后面会有n个整数,代表n维点的n个坐标值;如果od=1,代表删除点,删除的是第q条指令加入的点,而不是删除当前已有的第几个点。例如指令“1 5”,表示删除第5行的指令加入的点。
  不清楚最远曼哈顿距离怎么求的筒靴可以看这里:最远曼哈顿距离
  其实就是将绝对值去掉,移位,然后发现规律。多找几组例子对照着演算一下就容易明白了。
  明白基本原理了可以先看看一道最远曼哈顿距离的入门题:poj 2926:Requirements(最远曼哈顿距离,入门题)
  因为有删除操作,所以直接用数组会比较麻烦,这时候用STL中的映射表map和集合set就比较方便了。本来只想找一道类似的题,直接套我写的模板过的,结果找到这么一道还得用STL的题,表示很无奈,借机熟悉熟悉STL吧。好吧我承认我是参照着别人的代码才写出来。
  参考博客HDU 4666 Hyperspace
  代码:
 #include <iostream>
#include <iomanip>
#include <stdio.h>
#include <map>
#include <set>
using namespace std;
int main()
{
int i,j,k,q,dem;
while(scanf("%d%d",&q,&dem)!=EOF){
multiset <int> s[]; //定义多重集合
multiset <int>::iterator it1,it2;
map <int,int> m[]; //式子对点
int a[];
for(i=;i<=q;i++){
int od;
scanf("%d",&od);
if(od==){ //添加操作
for(j=;j<dem;j++)
scanf("%d",&a[j]);
for(j=;j<(<<(dem-));j++){ //用二进制形式遍历所有可能的运算情况
int sum = ;
for(k=;k<;k++){ //因为是五维的,所以有4个运算符
//提取当前运算符
int t = j & <<k; //1为+,0为-
if(t) sum+=a[k];
else sum-=a[k];
}
s[j].insert(sum);
m[j][i] = sum;
}
}
else{ //删除
int t;
scanf("%d",&t);
for(j=;j<(<<(dem-));j++){
if(m[j].size()>){
s[j].erase(s[j].find(m[j][t]));
m[j].erase(t);
}
}
}
int Max = ;
for(j=;j<(<<(dem-));j++){
if(s[j].size()>){
it1 = s[j].begin();
it2 = s[j].end();
it2--;
Max = *it2-*it1 > Max? *it2-*it1 : Max;
}
}
printf("%d\n",Max);
}
}
return ;
}

Freecode : www.cnblogs.com/yym2013

hdu 4666:Hyperspace(最远曼哈顿距离 + STL使用)的更多相关文章

  1. [HDU 4666]Hyperspace[最远曼哈顿距离][STL]

    题意: 许多 k 维点, 求这些点之间的最远曼哈顿距离. 并且有 q 次操作, 插入一个点或者删除一个点. 每次操作之后均输出结果. 思路: 用"疑似绝对值"的思想, 维护每种状态 ...

  2. HDU 4666 最远曼哈顿距离

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4666 关于最远曼哈顿距离的介绍: http://blog.csdn.net/taozifish/ar ...

  3. poj 2926:Requirements(最远曼哈顿距离,入门题)

    Requirements Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 3908   Accepted: 1318 Desc ...

  4. HDU 4666 Hyperspace (最远曼哈顿距离)

    Hyperspace Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Tota ...

  5. HDU 4666 Hyperspace (2013多校7 1001题 最远曼哈顿距离)

    Hyperspace Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Tota ...

  6. 多校联赛7 1001 hdu 4666(最远哈曼顿距离+优先队列)

    吐个糟,尼玛今天被虐成狗了,一题都没搞出来,这题搞了N久居然还是搞不出来,一直TLE,最后还是参考别人代码才领悟的,思路就这么简单, 就是不会转弯,看着模板却不会改,艹,真怀疑自己是不是个笨蛋题意:求 ...

  7. 2018 Multi-University Training Contest 10 CSGO(HDU - 6435)(最远曼哈顿距离)

    有 n 种主武器,m 种副武器.每种武器有一个基础分数k种属性值 X[i] . 选出一种主武器 mw 和一种副武器 sw,使得两种武器的分数和 + 每个属性的差值尽量大.(参考下面的式子) 多维的最远 ...

  8. POJ-2926 Requirements 最远曼哈顿距离

    题目链接:http://poj.org/problem?id=2926 题意:求5维空间的点集中的最远曼哈顿距离.. 降维处理,推荐2009武森<浅谈信息学竞赛中的“0”和“1”>以及&l ...

  9. Codeforces 491B. New York Hotel 最远曼哈顿距离

    最远曼哈顿距离有两个性质: 1: 对每一个点(x,y)  分别计算  +x+y , -x+y , x-y , -x-y 然后统计每种组合的最大值就能够了, 不会对结果产生影响 2: 去掉绝对值 , 设 ...

随机推荐

  1. centOS下yum安装配置samba

     centOS下yum安装配置samba 2010-03-29 15:46:00 标签:samba yum centOS 安装 休闲 注意:本文的原则是只将文件共享应用于内网服务器,并让将要被共享的目 ...

  2. jquery 使用方法<转载>

    jquery 使用方法 jQuery是目前使用最广泛的javascript函数库.据统计,全世界排名前100万的网站,有46%使用jQuery,远远超过其他库.微软公司 甚至把jQuery作为他们的官 ...

  3. UISearchBar和 UISearchDisplayController的使用

    感觉好多文章不是很全面,所以本文收集整合了网上的几篇文章,感觉有互相补充的效果. 如果想下载源码来看:http://code4app.com/search/searchbar .本源码与本文无关 1. ...

  4. 使用stty修改终端设置 stty 用法!

    在linux/unix平台上的 sqlplus中,如果输错了字符,要想删除,习惯性的按下backspace键后,发现非但没有删除想要删掉的字符,还多出了两个字符^H.当然,我们 可以同时按下ctrl+ ...

  5. form表单那点事儿(下) 进阶篇

    form表单那点事儿(下) 进阶篇 上一篇主要温习了一下form表单的属性和表单元素,这一片主要讲解用JavaScript如何操作form. 目录: 表单操作 取值 赋值 重置 校验 提交 技巧 不提 ...

  6. jquery 调用数据

    <body> <div id="aa" style="">hello</div> <div class="b ...

  7. Ninth scrum meeting - 2015/11/3

    今天课上老师询问了每个团队的进度,我们发现有好多团队都已经基本完成了, 距离预定的alpha版本开发完成时间也越来越近了,我们的工作也都在有条不紊的进行着.今天又出现了git pull时有冲突的情况, ...

  8. 第16章 使用Squid部署代理缓存服务

    章节概述: 本章节从代理缓存服务的工作原理开始讲起,让读者能够清晰理解正向代理(普通模式.透明模式)与反向代理的作用. 正确的使用Squid服务程序部署代理缓存服务可以有效提升访问静态资源的效率,降低 ...

  9. Linux中常用的查看系统信息的命令

    导读 Linux是一个神奇而又高效的操作系统,学完Linux对Linux系统有一个熟悉的了解后,你需要了解下这些实用的查看系统信息的命令. 查看系统版本命令 uname 谈到系统版本就一定会想到una ...

  10. i686和x86_64的区别

    找回TCL隐藏分区(转载) 用Wubi安装 Ubuntu 出现(Initranfs)问题的解决方案 i686和x86_64的区别 2009-04-11 08:19:31|  分类: 电脑问题 |  标 ...