HDU 4666 Hyperspace
来源:互联网 发布:淘宝能卖的香烟 编辑:程序博客网 时间:2024/06/09 16:51
题目意思:给出m维空间的n个坐标,求它的最大哈曼顿距离
题目分析:枚举出所有组号情况,并用优先队列维护
下面是AC代码:
#include <cstdio>#include <algorithm>#include <queue>#include <cstring>#include <iostream>using namespace std;#define N 60010#define inf 0x3fffffffint q, k, a[5];bool vis[N];struct node1 { int x, id; bool operator<(const node1& a) const { return x < a.x; }}t1;struct node2 { int x, id; bool operator<(const node2& a) const { return x > a.x; }}t2;priority_queue<node1> q1[1<<5];priority_queue<node2> q2[1<<5];int main() { while (scanf("%d%d", &q, &k) == 2) { int t; memset(vis, false, sizeof(vis)); for (int i=0; i<(1<<k); i++) { while (!q1[i].empty()) q1[i].pop(); while (!q2[i].empty()) q2[i].pop(); } int c, ans, mi, mx; for (int p=1; p<=q; p++) { scanf("%d", &t); if (t == 0) { for (int i=0; i<k; i++) scanf("%d", &a[i]); for (int s=0; s<(1<<k); s++) {//枚举所有子集 c = 0; for (int i=0; i<k; i++)//求和 if ((1<<i) & s) c += a[i]; else c -= a[i]; t1.x = t2.x = c; t1.id = t2.id = p; q1[s].push(t1); q2[s].push(t2); } } else { scanf("%d", &c); vis[c] = true; } ans = 0; for (int s=0; s<(1<<k); s++) { while (true) { t1 = q1[s].top(); if (!vis[t1.id]) break; q1[s].pop(); } while (true) { t2 = q2[s].top(); if (!vis[t2.id]) break; q2[s].pop(); } ans = max(ans, t1.x-t2.x); } printf("%d\n", ans); } } return 0;}
0 0
- HDU 4666 Hyperspace
- hdu-4666 Hyperspace
- hdu 4666 Hyperspace
- HDU 4666 Hyperspace
- hdu 4666 Hyperspace
- HDU 4666 Hyperspace
- hdu 4666Hyperspace
- HDU 4666 Hyperspace
- HDU 4666 Hyperspace
- HDU——4666 Hyperspace
- HDU 4666 Hyperspace 解题报告
- Hdu-4666 Hyperspace(曼哈顿距离)
- hdu 4666 Hyperspace 多校第七场
- hdu-4666-Hyperspace-最长曼哈顿距离
- [HDU 4666]Hyperspace[最远曼哈顿距离][STL]
- hdu 4666 Hyperspace (曼哈顿距离+set )
- [HDU 4666]Hyperspace[最远曼哈顿距离][STL]
- HDU 4666 Hyperspace(最长曼哈顿距离)
- 内存泄漏工具
- 团队沟通
- Java中的深拷贝和浅拷贝
- openstack学习笔记 --- glance 客户端管理镜像image
- 用angularjs遇到的一些问题及解决方案
- HDU 4666 Hyperspace
- 虫食算
- 第六周项目 3 完成第九章知识点思维导图
- 第八周——重载运算符——项目一(2)利用友元函数实现+-*/重载
- serialVersionUID作用
- 把android assets文件夹内的文件存储到sd卡中
- maven 中使用 json-lib 的小问题
- E - Super Jumping! Jumping! Jumping! HDU 1087 (基础动态规划)
- 黑马程序员——OC字符串,点语法,成员变量,@property和@synthetic,构造方法