hdu4666Hyperspace
http://acm.hdu.edu.cn/showproblem.php?pid=4666
先看一个求曼哈顿的帖子http://www.cnblogs.com/lmnx/articles/2479747.html
然后用mulityset进行维护下就可以了
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<set>
using namespace std;
#define N 60010
int w[N][];
int main()
{
int i,j,q,g,k;
while(cin>>q>>k)
{
multiset<int>p[];
multiset<int>::iterator it;
for(g = ; g <= q ; g++)
{
int a;
scanf("%d",&a);
if(a==)
{
for(i =; i < k ; i++)
scanf("%d",&w[g][i]);
for(i = ; i < <<k ; i++)
{
int temp = ;
for(j = ; j < k ; j++)
{
if(i&(<<j))
temp+=w[g][j];
else
temp-=w[g][j];
}
p[i].insert(temp);
}
}
else
{
int x;
scanf("%d",&x);
for(i = ; i < <<k ; i++)
{
int temp=;
for(j = ; j < k ; j++)
{
if(i&(<<j))
temp+=w[x][j];
else
temp-=w[x][j];
}
it = p[i].find(temp);
p[i].erase(it);
}
}
int maxz=;
for(i = ; i < <<k ; i++)
{
j =(~i)&((<<k)-);
int t1,t2;
it = p[i].end();
it--;
t1 = (*it);
it = p[j].end();
it--;
t2 = (*it);
maxz = max(maxz,t1+t2);
}
cout<<maxz<<endl;
}
}
return ;
}
hdu4666Hyperspace的更多相关文章
随机推荐
- someExperience
// 面试题1 var name = 'World'; (function () { if (typeof name==='undefined') { var name = 'jack'; conso ...
- 常用终端及git命令
终端常用命令 1,打开终端,git version 查看版本 2,pwd 打印工作目录 3,ls(list简写)查看当前目录的所有文件 4,clear 清掉屏幕 5,cd (change direct ...
- 二叉搜索的各种bugs——重复递增序列
int binary_search(int* A, int value, int p, int r); int main(int argc, char *argv[]){ , , , , , , , ...
- vim 的 tags 模块 与 ctags
1. 概述 一般来说,在代码中跳转,离不开 ctags. 实际上,vim 中代码跳转是由 vim tags 模块完成的,tags 模块依赖于 tags 文件. ctags(Generate tag f ...
- bzoj 2734 [HNOI2012]集合选数 状压DP+预处理
这道题很神啊…… 神爆了…… 思路大家应该看别的博客已经知道了,但大部分用的插头DP.我加了预处理,没用插头DP,一行一行来,速度还挺快. #include <cstdio> #inclu ...
- C++ const修饰函数、函数参数、函数返回值
const修饰函数 在类中将成员函数修饰为const表明在该函数体内,不能修改对象的数据成员而且不能调用非const函数.为什么不能调用非const函数?因为非const函数可能修改数据成员,cons ...
- IE兼容性问题
1.H5标签兼容.解决:js:document.createElement("footer");css:display: block;或者直接使用 html5shiv.js ...
- jQuery关于导航条背景切换
效果如下: <DOCTYPE html> <html> <head> <script src="http://code.jquery.com/jqu ...
- NetBeans中文乱码解决办法
一.Windows下NetBeans中文乱码解决办法 找到你的Netbeans安装目录下的etc文件夹,用记事本打开netbeans.conf,找到netbeans_default_options(不 ...
- 全面认识UML类图元素
本节和大家一起学习一下UML类图元素,类图能出色地表示继承与合成关系.为了将UML类图作为一种高效的沟通工具使用,开发者必须理解如何将类图上出现的元素转换到Java中.请看本节详细介绍. 全面认识UM ...