HDU 4666 Hyperspace
来源:互联网 发布:彩虹六号围攻优化 编辑:程序博客网 时间:2024/06/10 01:43
Hyperspace
Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)
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
来自http://blog.csdn.net/rowanhaoa/article/details/9970399的解题报告:
题意:
给定一些操作(0代表添加一个点,1代表删除一个点),求这些点的最远曼哈顿距离。
做法:
只考虑二维空间上两个坐标之间的曼哈顿距离(x1, y1) 和 (x2, y2),|x1-x2| +|y1-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)
显然,任意给两个点,我们分别计算上述四种情况,那么最大值就是曼哈顿距离。
转化后,“-”号两侧的坐标形式是一样的。维数为5,因此我们可以用二进制枚举。
最大曼哈顿距离 = max{每种情况下的最大值-最小值};
用multiset存储每种情况的值。
#include<cstdio>#include<cstring>#include<iterator>#include<set>using namespace std;struct Node{int v;int ff;};multiset<Node> num[1<<5];int Hash[61100];bool operator <(Node a,Node b){return a.v<b.v;}int main(){int i,j,cnt,flag,tmp;int q,k;int max,ok;Node s;int nn[10];multiset<Node>::iterator sta,tt;multiset<Node>::reverse_iterator end;while(scanf("%d%d",&q,&k)==2){for(i=0;i<1<<k;i++)num[i].clear();for(cnt=1;cnt<=q;cnt++){Hash[cnt]=1;scanf("%d",&flag);if(!flag){for(i=0;i<k;i++)scanf("%d",&nn[i]);s.ff=cnt;for(i=0;i<1<<k;i++){tmp=i;s.v=0;for(j=0;j<k;j++){if(tmp&1)s.v+=nn[j];elses.v-=nn[j];tmp>>=1;}num[i].insert(s);}}else{scanf("%d",&flag);Hash[flag]=0;}max=0;for(i=0;i<1<<k && !num[i].empty();i++){ok=1;while(ok && !num[i].empty()){ok=0;sta=num[i].begin();if(Hash[sta->ff]==0){num[i].erase(sta);ok=1;}}if(num[i].empty())break;ok=1;while(ok){ok=0;end=num[i].rbegin();if(Hash[end->ff]==0){num[i].erase(*end);ok=1;}}if(end->v-sta->v>max)max=end->v-sta->v;}printf("%d\n",max);}}return 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(最长曼哈顿距离)
- http状态码
- Windows Socket 最大连接数
- 黑马程序员_IO流入门讲解
- 多浏览器支持之 IE11【让程序支持IE11】
- Extjs学习总结---RowExpander 的异步调用
- HDU 4666 Hyperspace
- HQL具体用法
- Extjs学习总结---RowExpander 的异步调用
- .NET Remoting
- IAR MCS-51 v7.51A 软件注册机下载
- 类对象创建时占用内存
- 学Android开发啦啦啦啦啦啦啦啦啦
- 黑马程序员-Java多线程同步器CyclicBarrier
- DB2数据库的优化