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 ...
随机推荐
- maven的初步理解
[情景] 在进行JAVA项目开发的过程中,代码写好后,需要经过编译.打包.运行.测试.部署等过程. 在JAVA项目的开发阶段,就会根据业务的需要引入许多jar包来实现功能,但我们需求的jar包本身可能 ...
- static变量和final变量
1.static变量 按照是否静态的对类成员变量进行分类可分两种:一种是被static修饰的变量,叫静态变量或类变量:另一种是没有被static修饰的变量,叫实例变量.两者的区别是: 对于静态变量在内 ...
- xshell 映射带跳板机服务器的端口到本地
1.配置xshell连接跳板机服务器: 2. 3.可用navicate等同过端口连接远程数据库.
- Laravel 中自定义日志目录
参考:https://laravel-china.org/articles/7125/custom-log-directory-in-laravel
- BootStrap的table表格的基本写法
代码如下: <!DOCTYPE html> <html> <head> <title>BootStrap的基础入门</title> < ...
- 关于函数strtok和strtok_r的使用要点和实现原理
strtok函数的使用是一个老生常谈的问题了.该函数的作用很大,争议也很大.以下的表述可能与一些资料有区别或者说与你原来的认识有差异,因此,我尽量以实验为证.交代一下实验环境是必要的,winxp+vc ...
- NIO-3网络通信(非阻塞)
import java.io.IOException; import java.net.InetSocketAddress; import java.nio.ByteBuffer; import ja ...
- VS code配置docker的shell环境
今天尝试了下使用docker来做虚拟机,几番折腾后终于搞定可以用了,但是想着每次都要在命令行敲半天也太恶心了,所以就找了一下可视化的管理工具 首先说下,我的docker主机环境是windows10,用 ...
- go chapter 10 函数 方法 struct的方法
1. struct的方法 // 定义struct type MyStruct struct{} // 定义方法 (那个对象可以回调)方法名(参数) 返回值 {} (s *MyStruct) FillS ...
- Docker应用系列(三)| 构建Consul集群
本示例基于Centos 7,在阿里云的三台机器上部署consul集群,假设目前使用的账号为release,拥有sudo权限. 由于Docker官方镜像下载较慢,可以开启阿里云的Docker镜像下载加速 ...