Hdu-4666 Hyperspace(曼哈顿距离)
来源:互联网 发布:ar学校 软件下载 编辑:程序博客网 时间:2024/05/16 07:05
The great Mr.Smith has invented a hyperspace particle generator. The device is very powerful. The device can generate a hyperspace. In the hyperspace, particle may appear and disappear randomly. At the same time a great amount of energy was generated.
However, the device is in test phase, often in a unstable state. Mr.Smith worried that it may cause an explosion while testing it. The energy of the device is related to the maximum manhattan distance among particle.
Particles may appear and disappear any time. Mr.Smith wants to know the maxmium manhattan distance among particles when particle appears or disappears.
However, the device is in test phase, often in a unstable state. Mr.Smith worried that it may cause an explosion while testing it. The energy of the device is related to the maximum manhattan distance among particle.
Particles may appear and disappear any time. Mr.Smith wants to know the maxmium manhattan distance among particles when particle appears or disappears.
In each case: In the first line, there are two integer q(number of particle appear and disappear event, ≤60000) and k(dimensions of the hyperspace that the hyperspace the device generated, ≤5). Then follows q lines. In each line, the first integer ‘od’ represents the event: od = 0 means this is an appear
event. Then follows k integer(with absolute value less then 4 × 10 7). od = 1 means this is an disappear event. Follows a integer p represents the disappeared particle appeared in the pth event.
10 20 208 4030 371 -1801 20 1069 -1920 418 -5251 51 10 2754 6350 -2491 9610 2954 -2516
074601456145614560251255718922
分析:一开始以为要上KD-TREE,后来看了题解发现有个很巧妙的做法,两点间的曼哈顿距离等于各个坐标的绝对值差之和,绝对值等于大数减小数,但是因为这道题的k很小,所以我们可以枚举每一位的情况然后暴力统计,假如维度为2,A(x1,y1) 和 B(x2,y2)间的距离 可能为 x1-x2+y1-y2,x1-x2+y2-y1,x2-x1+y1-y2,x2-x1+y2-y1这四种,移项后就是(x1+y1)+(-x2-y2),(x1-y1)+(-x2+y2),(-x1+y1)+(x2-y2),(-x1-y1)+(x2+y2),
A点每个坐标的符号正好和B相反,所以我们只需要用set去维护每种组合的最大值,然后再枚举所有组合和其对应组合相加就可以求出来答案了。
#include <bits/stdc++.h>using namespace std;typedef long long ll;int q,k,num,op,a[60005][6];multiset<int> s[1<<5];int got(int x,int y){ int tot = 0; for(int i = 1;i <= k;i++) if(y & (1<<(i-1))) tot += a[x][i]; else tot -= a[x][i]; return tot;}int got_max(int x){ if(s[x].size() == 0) return 0; set<int> :: iterator it = s[x].end(); it--; return *it;}int main(){ cin.sync_with_stdio(false); while(cin>>q>>k) { for(int i = 0;i < (1<<5);i++) s[i].clear(); for(int i = 1;i <= q;i++) { cin>>op; if(!op) { for(int j = 1;j <= k;j++) cin>>a[i][j]; for(int j = 0;j < (1<<k);j++) s[j].insert(got(i,j)); } else { cin>>num; for(int j = 0;j < (1<<k);j++) { multiset<int> :: iterator it = s[j].find(got(num,j)); s[j].erase(it); } } int ans = 0; for(int j = 0;j < (1<<k);j++) ans =max(got_max(j) + got_max((1<<k)-j-1),ans); cout<<ans<<endl; } }}
阅读全文
0 0
- Hdu-4666 Hyperspace(曼哈顿距离)
- hdu-4666-Hyperspace-最长曼哈顿距离
- [HDU 4666]Hyperspace[最远曼哈顿距离][STL]
- hdu 4666 Hyperspace (曼哈顿距离+set )
- [HDU 4666]Hyperspace[最远曼哈顿距离][STL]
- HDU 4666 Hyperspace(最长曼哈顿距离)
- HDU 4666 Hyperspace【最远曼哈顿距离+优先队列】
- 最远曼哈顿距离小结 poj 2926 Requirements&hdu 4666 Hyperspace
- 最远曼哈顿距离小结 poj 2926 Requirements&hdu 4666 Hyperspace
- HDOJ 4666 Hyperspace 最大曼哈顿距离
- hdoj 4666 Hyperspace 【最远曼哈顿距离】
- 2013 多校第七场 hdu 4666 Hyperspace(最远曼哈顿距离)
- hdu4666--Hyperspace--最远曼哈顿距离
- HDU-4666 最远曼哈顿距离
- hdu 4666 线段树+最大曼哈顿距离
- HDU 5762:曼哈顿距离
- HDU 4666 Hyperspace(STL set 最近哈密顿距离)
- HDU 4666 Hyperspace
- 分解质因数
- Java工程读取resources中资源文件路径问题
- ftp
- 谈谈异步编程
- hibernate初学8 多表操作之一对多操作
- Hdu-4666 Hyperspace(曼哈顿距离)
- 再探reverse_iterator和iterator的关系
- 智能电视盒·路由·手机·家用电脑
- java开发环境的搭建
- 乐观锁和悲观锁的区别
- 【leetcode】24. Swap Nodes in Pairs
- Shell中字符串的切割、拼接、比较、替换
- android MVP + dagger2 + Retrofit + Rxjava+okhttp android基础项目框架搭建(1)--之Dagger2引入
- cocos2d_x事件交互处理