Hyperspace

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

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
 

经典的求最远曼哈顿距离。

可以看相应的论文:2009年国家集训队武森论文

其实就是维护(1<<k)个堆的最大值和最小值。

可以参考POJ 2926

我用multiset实现的。

可以使用map或者优先队列

 /* **********************************************
Author : kuangbin
Created Time: 2013/8/13 18:25:38
File Name : F:\2013ACM练习\2013多校7\1001.cpp
*********************************************** */ #include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
using namespace std;
int a[][];
multiset<int>mst[<<]; int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int q,k;
while(scanf("%d%d",&q,&k)==)
{
for(int i = ;i < (<<k);i++)
mst[i].clear();
int od,x;
for(int i = ;i <= q;i++)
{
scanf("%d",&od);
if(od == )
{
for(int j = ;j < k;j++)
scanf("%d",&a[i][j]);
for(int j = ; j < (<<k); j++)
{
int s = ;
for(int t = ; t < k;t++)
if(j & (<<t))
s += a[i][t];
else s -= a[i][t];
mst[j].insert(s);
}
}
else
{
scanf("%d",&x);
for(int j = ; j < (<<k); j++)
{
int s = ;
for(int t = ; t < k;t++)
if(j & (<<t))
s += a[x][t];
else s -= a[x][t];
multiset<int>::iterator it = mst[j].find(s);
mst[j].erase(it);
}
}
int ans = ;
for(int j = ; j < (<<k);j++)
{
multiset<int>::iterator it = mst[j].end();
it--;
int t1 = (*it);
it = mst[j].begin();
int t2 = (*it);
ans = max(ans,t1-t2);
}
printf("%d\n",ans);
}
}
return ;
}

HDU 4666 Hyperspace (2013多校7 1001题 最远曼哈顿距离)的更多相关文章

  1. HDU 4696 Answers (2013多校10,1001题 )

    Answers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total S ...

  2. HDU 4686 Arc of Dream (2013多校9 1001 题,矩阵)

    Arc of Dream Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Tota ...

  3. HDU 4655 Cut Pieces(2013多校6 1001题 简单数学题)

    Cut Pieces Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)Total ...

  4. HDU 4611 Balls Rearrangement(2013多校2 1001题)

    Balls Rearrangement Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Othe ...

  5. HDU 4643 GSM (2013多校5 1001题 计算几何)

    GSM Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submiss ...

  6. hdu 4666:Hyperspace(最远曼哈顿距离 + STL使用)

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

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

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

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

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

  9. HDU 4666 最远曼哈顿距离

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

随机推荐

  1. 在C#中用MediaInfo获取视频或音频的属性

    MediaInfo是一个开源的获取视频或音频的信息的非常便利的工具,它本身就带有一个GUI界面,可以非常方便我们查看视频信息.但是,当我们写一些转码程序时,往往需要在程序中获取视频信息的时候. 以前我 ...

  2. 002_让你的linux虚拟终端五彩缤纷(1)——LS颜色设置

  3. 域名 DNS命令——dig

    dig命令详解   1.查看域名的A记录          # dig yahoo.com; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.10.rc1.e ...

  4. [你必须知道的.NET]第二十三回:品味细节,深入.NET的类型构造器

    发布日期:2008.11.2 作者:Anytao © 2008 Anytao.com ,Anytao原创作品,转贴请注明作者和出处. 说在,开篇之前 今天Artech兄在<关于Type Init ...

  5. [翻译]HLS实践

    最近公司项目没事做,课余实践研究一下技术,算是积累,也可以用到项目里,从零开始记录 HLS:Http Live Streaming 官方文档 https://developer.apple.com/s ...

  6. poj1475 Pushing Boxes(BFS)

    题目链接 http://poj.org/problem?id=1475 题意 推箱子游戏.输入迷宫.箱子的位置.人的位置.目标位置,求人是否能把箱子推到目标位置,若能则输出推的最少的路径,如果有多条步 ...

  7. sql获取的时间不能直接在c#中tostring成我们要的格式,要转化一下

    DateTime.Parse(Model.Rows[0]["datevalidbegin"].ToString()).ToString("yyyy-MM-dd" ...

  8. thinkphp5.0架构总览

    ThinkPHP5.0应用基于MVC(模型-视图-控制器)的方式来组织. MVC是一个设计模式,它强制性的使应用程序的输入.处理和输出分开.使用MVC应用程序被分成三个核心部件:模型(M).视图(V) ...

  9. 洛谷P3459 [POI2007]MEG-Megalopolis [树链剖分]

    题目传送门 MEG 题目描述 Byteotia has been eventually touched by globalisation, and so has Byteasar the Postma ...

  10. java 数组冒泡排序、转置(降序)

    1.java 数组冒泡排序 排序的基本原理(升序): 原始数据:  2 .1 .9 .0 .5 .3 .7 .6 .8: 第一次排序: 1  .2 .0 .5 .3 .7 .6 .8 .9 : 第二次 ...