HDU 4666 Hyperspace (2013多校7 1001题 最远曼哈顿距离)
Hyperspace
Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 67    Accepted Submission(s): 32
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.
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.
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
746
0
1456
1456
1456
0
2512
5571
8922
经典的求最远曼哈顿距离。
可以看相应的论文: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题 最远曼哈顿距离)的更多相关文章
- HDU 4696 Answers (2013多校10,1001题 )
		
Answers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total S ...
 - 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 ...
 - HDU 4655 Cut Pieces(2013多校6 1001题  简单数学题)
		
Cut Pieces Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)Total ...
 - HDU 4611 Balls Rearrangement(2013多校2 1001题)
		
Balls Rearrangement Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Othe ...
 - HDU 4643 GSM (2013多校5 1001题  计算几何)
		
GSM Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submiss ...
 - hdu 4666:Hyperspace(最远曼哈顿距离 + STL使用)
		
Hyperspace Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Tota ...
 - [HDU 4666]Hyperspace[最远曼哈顿距离][STL]
		
题意: 许多 k 维点, 求这些点之间的最远曼哈顿距离. 并且有 q 次操作, 插入一个点或者删除一个点. 每次操作之后均输出结果. 思路: 用"疑似绝对值"的思想, 维护每种状态 ...
 - HDU  4666  Hyperspace (最远曼哈顿距离)
		
Hyperspace Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Tota ...
 - HDU 4666 最远曼哈顿距离
		
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4666 关于最远曼哈顿距离的介绍: http://blog.csdn.net/taozifish/ar ...
 
随机推荐
- juery给所有ID属性相同的div绑定一个事件
			
案例: <div id="div1">内容</div> <div id="div1">内容</div> < ...
 - python的sorted函数对字典按value进行排序
			
场景:词频统计时候,我们往往要对频率进行排序 sorted(iterable,key,reverse),sorted一共有iterable,key,reverse这三个参数.其中iterable表示可 ...
 - [ python ]  进程的操作
			
目录 (见右侧目录栏导航)- 1. 前言- 2. multiprocess模块- 2.1 multiprocess.Process模块 - 2.2 使用Process模块创建进程 - 2. ...
 - java版云笔记(三)
			
登录与注册写好了下来就是主页,今天写的是主页加载时笔记本列表的显示,ajax是固定的就不重点说了.主要说一下jQuery.data() 函数和jQuery.on() 函数. 注:这个项目的sql文件, ...
 - acm专题---最小生成树
			
kruscal(eloge): 题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=1102 Problem Description There are N ...
 - 20165301陈潭飞2017-2018-2 20165301 实验三《Java面向对象程序设计》实验报告
			
2017-2018-2 20165301 实验三<Java面向对象程序设计>实验报告 一.敏捷开发与XP实践-1 实验要求: 在IDEA中使用工具(Code->Reformate C ...
 - LeetCode301. Remove Invalid Parentheses
			
Remove the minimum number of invalid parentheses in order to make the input string valid. Return all ...
 - First Missing Positive——数学类
			
转:http://blog.csdn.net/nanjunxiao/article/details/12973173 Given an unsorted integer array, find the ...
 - bzoj 2115 线性基
			
这种路径异或问题,可以转换为一条路径和若干个环的线性组合,然后就能用线性基搞了. 复习了一波线性基. #include<bits/stdc++.h> #define LL long lon ...
 - 转:php防止sql注入的一点心得
			
转:http://blog.csdn.net/sky_zhe/article/details/9702489 转:http://zhangxugg-163-com.iteye.com/blog/183 ...