曼哈顿距离,两个点设为(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的更多相关文章

  1. hdu 4666:Hyperspace(最远曼哈顿距离 + STL使用)

    Hyperspace Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Tota ...

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

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

  3. HDU 4666 Hyperspace (最远曼哈顿距离)

    Hyperspace Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Tota ...

  4. HDU 4666 Hyperspace (2013多校7 1001题 最远曼哈顿距离)

    Hyperspace Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Tota ...

  5. hdu 4666 Hyperspace(多维度最远曼哈顿距离)

    献上博文一篇http://hi.baidu.com/byplane747/item/53ca46c159e654bc0d0a7b8d 设维度为k,维护(1<<k)个优先队列,用来保存0~( ...

  6. [HDU 4666]Hyperspace[最远曼哈顿距离][STL]

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

  7. HDU 4666

    http://acm.hdu.edu.cn/showproblem.php?pid=4666 求m维最远曼哈顿距离 借鉴别人的思路http://www.cnblogs.com/jackge/archi ...

  8. HDU 4666 最远曼哈顿距离

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4666 关于最远曼哈顿距离的介绍: http://blog.csdn.net/taozifish/ar ...

  9. hdu 4666 最大曼哈顿距离

    思路:这题我是看了题目后,上百度搜了一下才知道还有求最大曼哈顿距离的方法.直接把代码copy过来,研读一下,知道了代码实现机制,自然就很容易想到用优先队列来维护每种状态下的xi,yi之和的最大值最小值 ...

随机推荐

  1. http发送post请求

    package com.j1.soa.resource.member.oracle.service; import java.io.BufferedReader; import java.io.IOE ...

  2. SpringMvc之@RequestParam详解

    @RequestParam是传递参数的. @RequestParam用于将请求参数区数据映射到功能处理方法的参数上. public String queryUserName(@RequestParam ...

  3. Linux命令之文件与用户权限

    1.文件管理 在Linux里,任何软件和I/O设备都被视为文件.Linux中的文件名最大支持256个字符,分别可以用A-Z.a-z.0-9等字符来命名. 和Windows不同,Linux中文件是区分大 ...

  4. Android系统中长按事件的实现机制解析

    在Android的触摸消息中,已经实现了三种监测,它们分别是 1)pre-pressed:对应的语义是用户轻触(tap)了屏幕 2)pressed:对应的语义是用户点击(press)了屏幕 3)lon ...

  5. channel c3 disabled, job failed on it will be run on another channel

    今天执行备份时,报错: allocated channel: c3 channel c3: sid=131 instance=orcl2 devtype=DISK   RMAN-03009: fail ...

  6. UVA 1344 Tian Ji -- The Horse Racing

    Tian Ji -- The Horse Racing Here is a famous story in Chinese history. That was about 2300 years ago ...

  7. PHP实现对MongoDB的基础操作

    PHP扩展                                                                                      PHP5.2.PH ...

  8. ie6里png图片不透明

    ie6下img图片或背景图片为png时,图片变成了一片黑色: 图中的jquery-timepicker的两个黑方块和img就是由此原因引用的.解决方法:由Drew Diller提供,对img.back ...

  9. php代码生成二维码

    //引用范例 1 public function index() { 2 echo "<img src='http://qr.liantu.com/api.php?bg=f3f3f3& ...

  10. libevent入门(1)

    libevent是什么                libevent 库实际上没有更换 select().poll() 或其他机制的基础.而是使用对于每个平台最高效的高性能解决方案在实现外加上一个包 ...