HDU4666 Hyperspace(曼哈顿)
题目链接。
分析:
这是多校的一个题,当时没做出来。学长说让用multiset。
用multiset将每一个数的1<<dim个状态全部保存。假设状态 i, 最远曼哈顿距离应当是 max[i]-min[i], 但如果知道 i 的相反的状态就可以转化成 max[i]+min[(~i)&(1<<dim-1)]. 这和 x-y = x + (-y) 是一个道理.
AC代码如下:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <queue>
#include <stack>
#include <set> using namespace std; const int maxn = +;
const int dem = ; //维数
const int INF = (<<); int dim, x[maxn][dem]; int main(){
int n, ord; while(scanf("%d %d", &n, &dim) == ) {
multiset<int> ms[];
multiset<int>::iterator it; for(int i=; i<=n; i++) {
scanf("%d", &ord);
if(ord == ) {
for(int j=; j<dim; j++) {
scanf("%d", &x[i][j]);
} for(int j=; j<(<<dim); j++) {
int t = j, s = ;
for(int k=; k<dim; k++) {
if(t & ) s += x[i][k];
else s -= x[i][k];
t >>= ;
}
ms[j].insert(s);
} } else { //ord == 1 scanf("%d", &ord);
for(int j=; j<<<dim; j++) {
int t = j, s = ;
for(int k=; k<dim; k++) {
if(t & ) s += x[ord][k];
else s -= x[ord][k];
t >>= ;
} it = ms[j].find(s);
ms[j].erase(it);
}
} int ans = ;
for(int j=; j<(<<dim); j++) {
int k = ((~j) & ((<<dim)-));
int t1, t2;
it = ms[j].end(); //multiset内部是升序排列
it--;
t1 = *it;
it = ms[k].end();
it--;
t2 = *it;
ans = max(ans, t2+t1);
} printf("%d\n", ans);
}
} return ;
}
HDU4666 Hyperspace(曼哈顿)的更多相关文章
- hdu4666 Hyperspace ——曼哈顿距离
link:http://acm.hdu.edu.cn/showproblem.php?pid=4666 这题学会了怎么处理曼哈顿距离. 比如维数是k,那么每个点有2^k个状态,求出在每个状态下,所有点 ...
- HDU 4666 Hyperspace(曼哈顿距离)
题目链接 这是HDU第400个题. #include <cstdio> #include <cstring> #include <set> #include < ...
- 【 2013 Multi-University Training Contest 7 】
HDU 4666 Hyperspace 曼哈顿距离:|x1-x2|+|y1-y2|. 最远曼哈顿距离,枚举x1与x2的关系以及y1与y2的关系,取最大值就是答案. #include<cstdio ...
- hdu 4666:Hyperspace(最远曼哈顿距离 + STL使用)
Hyperspace Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Tota ...
- HDU 4666 Hyperspace (最远曼哈顿距离)
Hyperspace Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Tota ...
- HDU 4666 Hyperspace (2013多校7 1001题 最远曼哈顿距离)
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(多维度最远曼哈顿距离)
献上博文一篇http://hi.baidu.com/byplane747/item/53ca46c159e654bc0d0a7b8d 设维度为k,维护(1<<k)个优先队列,用来保存0~( ...
- hdu4666 最远曼哈顿距离
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4666 #include <cstdio> #include <cstring> ...
随机推荐
- [转载]Android利用convertView优化ListView性能
本的getView写法 Java代码public View getView(int position, View convertView, ViewGroup parent) {View view = ...
- 九度OnlineJudge之1001:A+B for Matrices
题目描述: This time, you are supposed to find A+B where A and B are two matrices, and then count the num ...
- cocos2d-x3.0 Physics新的物理引擎
1.说明: 3.0以后将box2d和chipmunk这两个物理引擎进行了封装,使用起来很的便利 2.详细用法: 1.创建物理世界场景 auto scene = Scene::createWithPhy ...
- XTU OJ 1210 Happy Number (暴力+打表)
Problem Description Recently, Mr. Xie learn the concept of happy number. A happy number is a number ...
- windows下如何设置mysql环境变量
方法一: windows下如何设置mysql环境变量 关键词: mysql, Setting Environment Variables, 环境变量设置 我的电脑->属性->高级-> ...
- 自定义控件(视图)2期笔记09:自定义视图之继承自ViewGroup(仿ViewPager效果案例)
1. 这里我们继承已有ViewGroup实现自定义控件,模拟出来ViewPager的效果,如下: (1)实现的效果图如下: (2)实现步骤: • 自定义view继承viewGroup • 重写onLa ...
- Linux学习方法之以始为终—Linux工作分类
/** ****************************************************************************** * @author 暴走的小 ...
- Cacti添加threshold、monitor和setting
Cacti版本:Version 0.8.8b 一.插件介绍: monitor:通过简单明了的图标提供服务器的运行状态 settings:给不同的插件提供一些共用的信息,如邮件信息,dns信息thold ...
- iOS 中Window优先级的问题
在项目中,视频播放时候遇到网络切换需要弹出AlertView提醒用户,忽然发现转屏的时候播放View加到KeyWindow的时候把AleryView挡住了.如图 因为转屏的时候视图是直接加载到 [UI ...
- 自己写的一个banner动画
html <div class="nav" > <div class="nav_son" id="nav"> < ...