link:http://acm.hdu.edu.cn/showproblem.php?pid=4666

这题学会了怎么处理曼哈顿距离。

比如维数是k,那么每个点有2^k个状态,求出在每个状态下,所有点的最大值,最小值,求他们的差,从中找到最大值就行。

开始觉得不好处理的是,删除的时候怎么办。比如要删除一个点,我可以在2^k个中的每个状态里面先找到这个点在这个状态下的值,删除这个值就行了。

 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <algorithm>
#include <queue>
#include <deque>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <functional>
#include <fstream>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <cassert>
#include <ctime>
#include <iterator>
const int INF = 0x3f3f3f3f;
const int dir[][] = {{-,},{,},{,-},{,},{-,-},{-,},{,-},{,}};
using namespace std;
multiset<int> a[];
int sad[][],will[][];
int main(void)
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif // ONLINE_JUDGE
int q,k;
while (~scanf("%d%d",&q,&k))
{
int apple=<<k;
for(int i=;i<;++i) a[i].clear();
for(int i=;i<q;++i)
{
int op; scanf("%d",&op);
if(op==)
{
for(int j=;j<k;++j)
{
scanf("%d",&sad[i][j]);
}
for(int j=;j<apple;++j)
{
int s=;
for(int pear=;pear<k;++pear)
{
if(j&(<<pear)) s+=sad[i][pear];
else s-=sad[i][pear];
}
will[i][j]=s;
a[j].insert(s);
}
}
else
{
int nu; scanf("%d",&nu);
for(int j=;j<apple;++j)
{
multiset<int>::iterator it;
it=a[j].find(will[nu-][j]);
if(it!=a[j].end())
a[j].erase(it);
}
}
int ans=;
for(int j=;j<apple;++j)
{
if(a[j].size()>)
{
int big=*(--a[j].end()),
small=*(a[j].begin());
// printf("big=%d small=%d\n",big,small);
if(big-small>ans) ans=big-small;
}
}
printf("%d\n",ans);
}
}
return ;
}

o(╯□╰)o

hdu4666 Hyperspace ——曼哈顿距离的更多相关文章

  1. HDU4666 Hyperspace(曼哈顿)

    题目链接. 分析: 这是多校的一个题,当时没做出来.学长说让用multiset. 用multiset将每一个数的1<<dim个状态全部保存.假设状态 i, 最远曼哈顿距离应当是 max[i ...

  2. HDU 4666 Hyperspace(曼哈顿距离)

    题目链接 这是HDU第400个题. #include <cstdio> #include <cstring> #include <set> #include < ...

  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 (最远曼哈顿距离)

    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. [HDU 4666]Hyperspace[最远曼哈顿距离][STL]

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

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

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

  8. Hdu4311 || 4312Meeting point-1/-2 n个点中任意选一个点使得其余点到该点曼哈顿距离之和最小

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission( ...

  9. Atitti knn实现的具体四个距离算法 欧氏距离、余弦距离、汉明距离、曼哈顿距离

    Atitti knn实现的具体四个距离算法  欧氏距离.余弦距离.汉明距离.曼哈顿距离 1. Knn算法实质就是相似度的关系1 1.1. 文本相似度计算在信息检索.数据挖掘.机器翻译.文档复制检测等领 ...

随机推荐

  1. Analyzer报表结果行

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

  2. What are the advantages of ReLU over sigmoid function in deep neural network?

    The state of the art of non-linearity is to use ReLU instead of sigmoid function in deep neural netw ...

  3. Redis - 作为 LRU 缓存

    一.简介 LRU 实际上是被唯一支持的数据移除方法,同时也是 memcached 默认支持的缓存算法. 二.配置内存大小 在 redis.conf 文件中使用 maxmemory 指令能够配置内存大小 ...

  4. 调度系统任务创建---创建一个MultiJob的任务(四)

    我们如果下面这种拓扑结构的调度任务,该任务的拓扑结构就是一个有向五环图DAG,有fork,有join的操作等. 可以通过jenkins创建MultiJob的任务实现: 实例任务的拓扑结构: Multi ...

  5. C/C++与Matlab混合编程

    Matlab 拥有丰富的功能,编程简单.不过,有些情况下,Matlab程序的执行速度比较慢.C/C++编译执行的程序速度比较快,编程难度上比Matlab要高一些.因此存在一种方案,就是使用Matlab ...

  6. div 一段时间后自动隐藏

    一.div弹出后自动消失 这里并没有删除 setTimeout(function(){$(".alert").hide();},2000); 直接在js文件中需要的地方添加执行这段 ...

  7. 中国Linux源镜像站大全

    原文链接:http://www.centoscn.com/yunwei/news/2012/1227/131.html 一.国内的linux源镜像站点: 1.企业源:阿里云开源镜像站: http:// ...

  8. combobox获取值

    easyui-combobox是组合框 ,既可以输入,也可以选择 获取的数据是json格式的  [{"id":"001","text":&q ...

  9. CAD字体显示问号的解决办法

    CAD字体显示问号的解决办法1.选中问号的文字,ctrl+1查看下文字样式,以standard为例.2.运行st命令,设置standard样式的字体名为windows自带的ttf字体,例如宋体或者仿宋 ...

  10. 再说最后一次!关于不再更新SkySRS的理由!

    再说最后一次!关于不再更新SkySRS的理由! https://www.itiankong.net/thread-195937-1-1.html Skyfree 发表于 2012-5-1 14:53: ...