hdu 4666 Hyperspace
曼哈顿距离,两个点设为(x1,y1),(x2,y2),其距离为|x1-x2|+|y1-y2|
#include <cstdio>
#include <set>
#include <cstring>
#include <cstdlib>
using namespace std;
struct node
{
int pos;
int sum;
bool operator < (const node &p) const
{
return p.sum>sum;
}
node (int x,int y)
{
pos=x;
sum=y;
}
};
set<node> s[34];
int n,m,cnt;
int f_a[34][5],v[5];
bool d[60010];
void dfs(int cur)
{
if(cur==m)
{
for(int i=0; i<m; ++i) f_a[cnt][i]=v[i];
s[cnt++].clear();
return;
}
v[cur]=1;
dfs(cur+1);
v[cur]=-1;
dfs(cur+1);
}
void solve(int cur)
{
for(int i=0; i<cnt; ++i)
{
int a=0;
for(int j=0; j<m; ++j) a+=v[j]*f_a[i][j];
s[i].insert(node(cur,a));
}
}
void del()
{
int sum=0;
for(int i=0; i<cnt; ++i)
{
set<node>::iterator p,q;
while(s[i].size())
{
p=s[i].begin();
if(d[p->pos]) s[i].erase(*p);
else break;
}
while(s[i].size())
{
q=s[i].end();
--q;
if(d[q->pos]) s[i].erase(*q);
else break;
}
if(!s[i].size()) continue;
sum=max(sum,q->sum - p->sum);
}
printf("%d\n",sum);
}
int main()
{
//freopen("in.txt","r",stdin);
while(scanf("%d%d",&n,&m)!=EOF)
{
int f,pos;
cnt=0;
memset(d,0,sizeof(bool)*(n+1));
dfs(0);
for(int i=1; i<=n; ++i)
{
scanf("%d",&f);
if(!f) for(int j=0; j<m; ++j) scanf("%d",&v[j]);
else
{
scanf("%d",&pos);
d[pos]=1;
}
if(!f) solve(i);
del();
}
}
return 0;
}
hdu 4666 Hyperspace的更多相关文章
- hdu 4666:Hyperspace(最远曼哈顿距离 + STL使用)
Hyperspace Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Tota ...
- HDU 4666 Hyperspace(曼哈顿距离)
题目链接 这是HDU第400个题. #include <cstdio> #include <cstring> #include <set> #include < ...
- 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(多维度最远曼哈顿距离)
献上博文一篇http://hi.baidu.com/byplane747/item/53ca46c159e654bc0d0a7b8d 设维度为k,维护(1<<k)个优先队列,用来保存0~( ...
- [HDU 4666]Hyperspace[最远曼哈顿距离][STL]
题意: 许多 k 维点, 求这些点之间的最远曼哈顿距离. 并且有 q 次操作, 插入一个点或者删除一个点. 每次操作之后均输出结果. 思路: 用"疑似绝对值"的思想, 维护每种状态 ...
- HDU 4666
http://acm.hdu.edu.cn/showproblem.php?pid=4666 求m维最远曼哈顿距离 借鉴别人的思路http://www.cnblogs.com/jackge/archi ...
- HDU 4666 最远曼哈顿距离
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4666 关于最远曼哈顿距离的介绍: http://blog.csdn.net/taozifish/ar ...
- hdu 4666 最大曼哈顿距离
思路:这题我是看了题目后,上百度搜了一下才知道还有求最大曼哈顿距离的方法.直接把代码copy过来,研读一下,知道了代码实现机制,自然就很容易想到用优先队列来维护每种状态下的xi,yi之和的最大值最小值 ...
随机推荐
- C# TextBox控件 显示大量数据
串口通信:在使用TextBox空间显示数据时,因为要显示大量的接收到的数据,当数据量大且快速(串口1ms发送一条数据)时,使用+=的方式仍然会造成界面的卡顿(已使用多线程处理),但使用AppendTe ...
- linux 下使用crontab+wget实现秒及定时任务
输入命令 crontab -e 打开一个文件,默认的编辑器为vi. 输入vi编辑器,输入i为插入,输入w保存,q退出,!强制.wq!强制保存并退出. * * * * * /usr/bin/wget - ...
- 使用Android平板编程,执行linux命令
android有一些应用支持开发, AIDE 介绍http://www.wandoujia.com/apps/com.aide.ui https://play.google.com/store/app ...
- C#实现窗体间的通信
以下将窗体间的几种通信实现方式做一下罗列:首先新建一个窗体Form1,在其中放置一个Textbox.Button控件.再新建一个窗体Form2,其上放置一个Button控件.具体代码示例如下: //F ...
- centos上安装rabbitmq并且python测试
把我的阿里云重置了一下,重新安装rabbitmq,看看会出现什么问题. 首先,把erlang环境安装一下,直接 yum list | grep erlang erlang.x86_64 R16B-03 ...
- jboss-AS目录结构了解(资料摘取)
Directory Description bin Contains startup, shutdown and other system-specific scripts. Basically al ...
- win8下nodejs安装配置记录
1:打开nodejs官网http://nodejs.org/ 下载安装版. 2:安装完成后,打开cmd输入node -v 查看是否安装成功: 3:安装express,通过全局安装方式进行安装: 安装完 ...
- EXTJS4:在grid中加入合计行
extjs4很方便的实现简单的合计(针对在不分页的情况下): 它效果实现在:Ext.grid.feature.Summary这个类中 Ext.define('TestResult', { extend ...
- 【转】Ubuntu 10.04 LTS 的窗口控制按钮从左上角调整到右上角
原文网址:http://www.linuxidc.com/Linux/2010-05/26111.htm 升级到Ubuntu 10.04后最大的问题,是最小最大和关闭按钮,放到了左边.这叫Ubuntu ...
- jquery点击按钮显示和隐藏DIv
function changeDisplay() { if ($("#btnShow").attr("value")== "添加附件") { ...