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. ios 正则邮箱

    - (BOOL) isEmail { NSString *emailRegEx = @"(?:[a-z0-9!#$%\\&'*+/=?\\^_`{|}~-]+(?:\\.[a-z0- ...

  2. python读写操作文件

    with open(xxx,'r,coding='utf-8') as f:   #打开文件赋值给F ,并且执行完了之后不需要 f.close(). 在Python 2.7 及以后,with又支持同时 ...

  3. Javascript动态调整文章的行距、字体、颜色,及打印页面和关闭窗口功能

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  4. WPF控件模拟双击事件

    Action a = () => { i += ; ) { Interval = }; timer.Elapsed += (sender, e) => { timer.Enabled = ...

  5. Java实现Socket5代理服务器

    直接贴代码,不解释 1 主服务,用来侦听端口 package org.javaren.proxy; import java.net.ServerSocket; import java.net.Sock ...

  6. webexam项目杂记

    sql 语句 数据库 本身 有数据类型的区分,对于mysql的字符串默认的用单引号''来表示,因此,整个sql 语句就要用双引号来括. 如: $sql = "SELECT * FROM us ...

  7. weblogic <BEA-000438>

    现在创建域并启动服务器, 或许会发现如下提示的错误信息:<Error> <Socket> <BEA-000438> <Unable to load perfo ...

  8. poj1258 Agri-Net 最小生成树

    Agri-Net Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 44032   Accepted: 18001 Descri ...

  9. HDU3348(贪心求硬币数

    ;} coins Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  10. BeautifulSoup获取指定class样式的div

    如何获取指定的标签的内容是解析网页爬取数据的必要手段,比如想获取<div class='xxx'> ...<div>这样的div标签,通常有三种办法, 1)用字符串查找方法,然 ...