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. 初学JDBC,防SQL注入简单示例

    在JDBC简单封装的基础上实现 public class UserDao{ public static void testGetUser(String userName) throws Excepti ...

  2. CSS 兼容 总结

    1> margin加倍的问题 设置为float的div在ie下设置的margin会加倍.这是一个ie6都存在的bug. 解决方案是在这个div里面加上display:inline; 例如: &l ...

  3. iOS多线程介绍

    一.线程概述 有些程序是一条直线,起点到终点:有些程序是一个圆,不断循环,直到将它切断.直线的如简单的Hello World,运行打印完,它的生命周期便结束了,像昙花一现那样:圆如操作系统,一直运行直 ...

  4. 转:this的用法

    this指针的含义及其用法: 1. this指针是一个隐含于每一个成员函数中的特殊指针.它指向正在被该成员函数操作的那个对象.2. 当对一个对象调用成员函数时,编译程序先将对象的地址赋给this指针, ...

  5. malloc 函数到底做了什么?

    请看下面的代码. 猜测结果是什么?编译通过吗? #include <stdio.h> #include <stdlib.h> int main() { ; char *ptr ...

  6. 交叉编译php5,、nginx、squid方法

    本文为原创,转载请注明:http://www.cnblogs.com/tolimit/ 交叉编译php5 软件版本:php-5.4.27 依赖库:zlib,libxml2 交叉编译器:arm-hisi ...

  7. Ninth scrum meeting - 2015/11/3

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

  8. navicat连接oracle报错ORA-12737: Instant Client Light: unsupported server character set CHS16GBK”

    原文如下http://blog.163.com/cp7618@yeah/blog/static/7023477720142154449893/?COLLCC=1318255100& 这个工具可 ...

  9. Python socket 详解

    socket()函数用于根据指定的地址族.数据类型和协议来分配一个套接口的描述字及其所用的资源.如果协议protocol未指定(等于0),则使用缺省的连接方式. 对于使用一给定地址族的某一特定套接口, ...

  10. HDOJ 1864 最大报销额(01背包)

    http://acm.hdu.edu.cn/showproblem.php?pid=1864 最大报销额 Time Limit: 1000/1000 MS (Java/Others)    Memor ...