Hyperspace

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

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
10 2
0 208 403
0 371 -180
1 2
0 1069 -192
0 418 -525
1 5
1 1
0 2754 635
0 -2491 961
0 2954 -2516
 
Sample Output
0
746
0
1456
1456
1456
0
2512
5571
8922
 
Source
 
Recommend
zhuyuanchen520

题意:给定一些操作(0代表添加一个点,1代表删除一个点),求这些点的最远曼哈顿距离。

可先参考POJ  2926  Requirements:http://poj.org/problem?id=2926

POJ该题思路:

以二维平面为例:

设距离最远的两点为 i, j,可知所求的最大距离必定有以下四种形式之一:

(xi-xj)+(yi-yj), (xj-xi)+(yi-yj), (xi-xj)+(yj-yi), (xj-xi)+(yj-yi) 变形一下,把相同点的坐标放到一起,

即 (xi+yi)-(xj+yj), (-xi+yi)-(-xj+yj), (xi-yi)-(xj-yj), (-xi-yi)-(-xj-yj),可以发现即去绝对值之后把同一点的坐标放在一起,对应坐标符号相同。

假如我们用0表示符号,用1表示正号,那么 (xi+yi) 可以表示为 11。

那么要表示一个维数为 dem 的所有状态,只需要用 0 ~ (2^dem-1) 的所有二进制就可以了。

于是只要对所有的点 (xi,yi),依次计算出 (xi+yi), (xi-yi), (-xi+yi), (-xi-yi)这四种形式,然后把每个点i算出来的这四种情况的最大值、最小值分别记录(更新)到数组 max[] 和 min[] 中,然后枚举每一种去绝对值的组合,组合后的最大值即为 answer。

代码:

#include<iostream>
#include<cstdio>
#include<cstring> using namespace std; const int N=;
const double INF=1e20; int n;
double num[N][],minx[<<],maxx[<<]; int main(){ //freopen("input.txt","r",stdin); while(~scanf("%d",&n)){
for(int i=;i<n;i++)
for(int j=;j<;j++)
scanf("%lf",&num[i][j]);
for(int i=;i<(<<);i++){ //共有(1<<5)种状态,存储每种状态下的最大最小值
minx[i]=INF;
maxx[i]=-INF;
}
double sum;
int tmp;
for(int i=;i<n;i++)
for(int j=;j<(<<);j++){ //枚举每种状态
tmp=j;
sum=;
for(int k=;k<;k++){
if(tmp&)
sum+=num[i][k];
else
sum-=num[i][k];
tmp>>=;
}
if(maxx[j]<sum)
maxx[j]=sum;
if(minx[j]>sum)
minx[j]=sum;
}
double ans=-INF;
for(int i=;i<(<<);i++)
if(maxx[i]-minx[i]>ans)
ans=maxx[i]-minx[i];
printf("%.2f\n",ans);
}
return ;
}
#include<iostream>
#include<cstdio>
#include<cstring>
#include<set> using namespace std; const int N=;
const double INF=1e20; int n,m,num[N][];
//map<int,int,greater<int> > mp[1<<5];
multiset<int> mst[<<];
multiset<int>::iterator it1,it2; int main(){ //freopen("input.txt","r",stdin); while(~scanf("%d%d",&n,&m)){
for(int i=;i<(<<);i++)
mst[i].clear();
int od,x;
for(int i=;i<=n;i++){
scanf("%d",&od);
if(od==){
for(int j=;j<m;j++)
scanf("%d",&num[i][j]);
for(int j=;j<(<<m);j++){
int sum=;
for(int k=;k<m;k++){
if(j&(<<k))
sum+=num[i][k];
else
sum-=num[i][k];
}
mst[j].insert(sum);
}
}else{
scanf("%d",&x);
for(int j=;j<(<<m);j++){
int sum=;
for(int k=;k<m;k++){
if(j&(<<k))
sum+=num[x][k];
else
sum-=num[x][k];
}
it1=mst[j].find(sum);
mst[j].erase(it1);
}
}
int ans=;
//map<int,int>::iterator it1,it2;
for(int j=;j<(<<m);j++){
it1=mst[j].end();
it1--;
it2=mst[j].begin();
ans=max(ans,(*it1)-(*it2));
}
printf("%d\n",ans);
}
}
return ;
}

HDU 4666 Hyperspace (最远曼哈顿距离)的更多相关文章

  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. hdu 4666:Hyperspace(最远曼哈顿距离 + STL使用)

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

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

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

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

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

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

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

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

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

  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. 你需要知道的 .NET

    1. 简述private.protected.public.internal 修饰符的访问权限. 答. private : 私有成员, 在类的内部才可以访问. protected : 保护成员,该类内 ...

  2. poj 2031 给出每个结点的3维坐标 以及结点的半径 (MST)

    3维空间中有N个圆球,给出x y z 以及圆球的半径 ,求最小生成树 边的权值为两个圆球间的距离 如果圆球相互接触 则权值为0 求最小的权值和 Sample Input 3 //n10.000 10. ...

  3. php 发送超大数据处理

    set_time_limit(0);//设置永不超时 ignore_user_abort(); //设置客户端断开,继续处理 //总数 $allusercount= $this->gamedb_ ...

  4. 020 RDD的理解

    一:源码介绍RDD 1.RDD介绍 五大特性,保证了Spark的扩展性,容错性等特性. A list of partitions ====> 一个许多分区的集合,分区中包含数据 A functi ...

  5. 如何查看Unity的版本

    打开Unity,Help->About Unity

  6. Ubuntu18.04更换国内源

    Ubuntu18.04更换国内源 Ubuntu本身的源使用的是国内的源,下载速度比较慢,不像CentOS一样yum安装的时候对镜像站点进项选择, 所以选择了更换成国内的源. 以下内容整合自网络 备份/ ...

  7. UVA725 Division 除法【暴力】

    题目链接>>>>>> 题目大意:给你一个数n(2 <= n <= 79),将0-9这十个数字分成两组组成两个5位数a, b(可以包含前导0,如02345 ...

  8. pwcrack--一款集合多种md5解密的工具

    项目开源地址:https://github.com/L-codes/pwcrack-framework Ruby2.5+ (tested with Ruby2.5.3 & Ruby 2.6.3 ...

  9. jenkins使用总结

    这个教程很全面,可以参考 https://www.jianshu.com/p/dceaa1c7bb49

  10. 搜索+剪枝——POJ 1011 Sticks

    搜索+剪枝--POJ 1011 Sticks 博客分类: 算法 非常经典的搜索题目,第一次做还是暑假集训的时候,前天又把它翻了出来 本来是想找点手感的,不想在原先思路的基础上,竟把它做出来了而且还是0 ...