HDOJ 4666 Hyperspace 最大曼哈顿距离
来源:互联网 发布:windows风格命名规则 编辑:程序博客网 时间:2024/04/30 18:03
二进制转化,求最大曼哈顿距离....
Hyperspace
Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 1123 Accepted Submission(s): 530
Problem Description
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.
Input
The input contains several test cases, terminated by EOF.
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 × 107). od = 1 means this is an disappear event. Follows a integer p represents the disappeared particle appeared in the pth event.
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 × 107). od = 1 means this is an disappear event. Follows a integer p represents the disappeared particle appeared in the pth event.
Output
Each test case should contains q lines. Each line contains a integer represents the maximum manhattan distance among paticles.
Sample Input
10 20 208 4030 371 -1801 20 1069 -1920 418 -5251 51 10 2754 6350 -2491 9610 2954 -2516
Sample Output
074601456145614560251255718922
Source
2013 Multi-University Training Contest 7
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <set>using namespace std;const int maxn=66000;int n,k,id;int mat[maxn][5];int pos[maxn];multiset<int> SET[50];void init(){ id=0; int nn=1<<k; for(int i=0;i<nn;i++) SET[i].clear();}int getSum(int id,int x){ int sum=0; for(int i=0;i<k;i++) { if(x&(1<<i)) sum+=mat[id][i]; else sum-=mat[id][i]; } return sum;}void add(int x){ int nn=1<<k; for(int i=0;i<nn;i++) { int xx=getSum(x,i); SET[i].insert(xx); }}void rm(int x){ int nn=1<<k; for(int i=0;i<nn;i++) { int xx=getSum(x,i); SET[i].erase(SET[i].find(xx)); }}int check(){ int nn=1<<k; int ans=0; for(int i=0;i<nn;i++) { multiset<int>::iterator S,E; S=SET[i].begin(); E=SET[i].end(); E--; ans=max(ans,*E-*S); } return ans;}int main(){ while(scanf("%d%d",&n,&k)!=EOF) { init(); int kind; for(int i=0;i<n;i++) { scanf("%d",&kind); if(kind==0) { for(int j=0;j<k;j++) { scanf("%d",&mat[id][j]); } add(id); pos[i+1]=id; id++; } else { int rmid; scanf("%d",&rmid); rm(pos[rmid]); } printf("%d\n",check()); } } return 0;}
0 0
- HDOJ 4666 Hyperspace 最大曼哈顿距离
- hdoj 4666 Hyperspace 【最远曼哈顿距离】
- Hdu-4666 Hyperspace(曼哈顿距离)
- hdoj 4666 Hyperspace 最大哈弗曼顿距离
- hdu-4666-Hyperspace-最长曼哈顿距离
- [HDU 4666]Hyperspace[最远曼哈顿距离][STL]
- hdu 4666 Hyperspace (曼哈顿距离+set )
- [HDU 4666]Hyperspace[最远曼哈顿距离][STL]
- HDU 4666 Hyperspace(最长曼哈顿距离)
- hdu4666--Hyperspace--最远曼哈顿距离
- HDU 4666 Hyperspace【最远曼哈顿距离+优先队列】
- 最远曼哈顿距离小结 poj 2926 Requirements&hdu 4666 Hyperspace
- 最远曼哈顿距离小结 poj 2926 Requirements&hdu 4666 Hyperspace
- 2013 多校第七场 hdu 4666 Hyperspace(最远曼哈顿距离)
- hdu 4666 线段树+最大曼哈顿距离
- 【水题】 HDOJ 4666 Hyperspace
- 【最大曼哈顿距离】POJ2926 Requirements
- hdoj 5626 Clarke and points (曼哈顿距离)
- 解读Spring LDAP帮助中的代码案例(二)
- 强连通分量,自用!
- Activity单例模式与onNewIntent
- 二叉树笔试面试题小结
- myeclipse10 安装SVN插件
- HDOJ 4666 Hyperspace 最大曼哈顿距离
- 关于0-1矩阵置1的问题
- ENC28J60学习笔记1
- USACO: Transformation
- 淘宝技术发展
- HDOJ 4671 Backup Plan 构造优先队列
- HDU 3709 Balanced Number
- metasploit渗透测试学习笔记(一)
- socket系列之什么是socket