poj 2926 Requirements (曼哈顿距离)
2016-07-28 20:21
393 查看
题目链接
题目描述:
Hyperspace
Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 1262 Accepted Submission(s): 611
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.
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.
Output
Each test case should contains q lines. Each line contains a integer represents the maximum manhattan distance among paticles.
Sample Input
10 2
0 208 403
0 371 -180
1 2
0 1069 -192
0 418 -525
1 5
1 1
0 2754 635
0 -2491 961
0 2954 -2516
Sample Output
0
746
0
1456
1456
1456
0
2512
5571
8922
题意:
给出n个5维点,计算两点的曼哈顿距离的最大值。
题解:
传送门~
题目描述:
Hyperspace
Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 1262 Accepted Submission(s): 611
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.
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.
Output
Each test case should contains q lines. Each line contains a integer represents the maximum manhattan distance among paticles.
Sample Input
10 2
0 208 403
0 371 -180
1 2
0 1069 -192
0 418 -525
1 5
1 1
0 2754 635
0 -2491 961
0 2954 -2516
Sample Output
0
746
0
1456
1456
1456
0
2512
5571
8922
题意:
给出n个5维点,计算两点的曼哈顿距离的最大值。
题解:
传送门~
#include<iostream> #include<cstdio> #include<cmath> #include<algorithm> using namespace std; const int maxn=1e5+5; const double inf=0x3f3f3f3f; double a[maxn][6]; int main() { int n; while(~scanf("%d",&n)) { for(int i=1;i<=n;i++) for(int j=1;j<=5;j++) scanf("%lf",&a[i][j]); double ans=0; for(int i=0;i<(1<<5);i++) { double mx=-inf,mi=inf; for(int j=1;j<=n;j++) { double p=0; for(int k=0;k<5;k++) { if(i&(1<<k)) p+=a[j][k+1]; else p-=a[j][k+1]; } mx=max(mx,p); mi=min(mi,p); } ans=max(ans,mx-mi); } printf("%.2lf\n",ans); } }
相关文章推荐
- UE4 万能锁的一种解法
- UIButton属性详解
- Hive 的分桶 & Parquet 概念
- input文本框中value值有双引号的问题
- 高精度运算-424 integer inquiry
- 玩转iOS开发:《使用系统自定义UIActivity进行内容分享》
- 虚幻4 制作UI粒子系统插件
- easyUI前后台分页代码实现
- STL学习之路(一) deque
- 虚幻4 创建选择资源的UI
- easyui
- Required field 'sessionHandle is unset !’
- 解决macro "__TIME__" might prevent reproducible builds [-Werror=date-time]错误
- tornado RequestHandler request.body & request.arguments
- Method to remove Tablet nav
- java语言基础入门——String、StringBuffer、StringBuilder的比较
- Error in XmlSqlMapClientBuilder. Alias name conflict occurred.
- easyui的导入和使用
- UIScrollView下拉实现图片放大或缩小
- IOS-- UIView中的坐标转换