hdu 4666:Hyperspace(最远曼哈顿距离 + STL使用)
Hyperspace
Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 1023 Accepted Submission(s): 492
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 × 107). od = 1 means this is an disappear event. Follows a integer p represents the disappeared particle appeared in the pth event.
- -
- -
-
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <map>
#include <set>
using namespace std;
int main()
{
int i,j,k,q,dem;
while(scanf("%d%d",&q,&dem)!=EOF){
multiset <int> s[]; //定义多重集合
multiset <int>::iterator it1,it2;
map <int,int> m[]; //式子对点
int a[];
for(i=;i<=q;i++){
int od;
scanf("%d",&od);
if(od==){ //添加操作
for(j=;j<dem;j++)
scanf("%d",&a[j]);
for(j=;j<(<<(dem-));j++){ //用二进制形式遍历所有可能的运算情况
int sum = ;
for(k=;k<;k++){ //因为是五维的,所以有4个运算符
//提取当前运算符
int t = j & <<k; //1为+,0为-
if(t) sum+=a[k];
else sum-=a[k];
}
s[j].insert(sum);
m[j][i] = sum;
}
}
else{ //删除
int t;
scanf("%d",&t);
for(j=;j<(<<(dem-));j++){
if(m[j].size()>){
s[j].erase(s[j].find(m[j][t]));
m[j].erase(t);
}
}
}
int Max = ;
for(j=;j<(<<(dem-));j++){
if(s[j].size()>){
it1 = s[j].begin();
it2 = s[j].end();
it2--;
Max = *it2-*it1 > Max? *it2-*it1 : Max;
}
}
printf("%d\n",Max);
}
}
return ;
}
Freecode : www.cnblogs.com/yym2013
hdu 4666:Hyperspace(最远曼哈顿距离 + STL使用)的更多相关文章
- [HDU 4666]Hyperspace[最远曼哈顿距离][STL]
题意: 许多 k 维点, 求这些点之间的最远曼哈顿距离. 并且有 q 次操作, 插入一个点或者删除一个点. 每次操作之后均输出结果. 思路: 用"疑似绝对值"的思想, 维护每种状态 ...
- HDU 4666 最远曼哈顿距离
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4666 关于最远曼哈顿距离的介绍: http://blog.csdn.net/taozifish/ar ...
- poj 2926:Requirements(最远曼哈顿距离,入门题)
Requirements Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 3908 Accepted: 1318 Desc ...
- HDU 4666 Hyperspace (最远曼哈顿距离)
Hyperspace Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Tota ...
- HDU 4666 Hyperspace (2013多校7 1001题 最远曼哈顿距离)
Hyperspace Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Tota ...
- 多校联赛7 1001 hdu 4666(最远哈曼顿距离+优先队列)
吐个糟,尼玛今天被虐成狗了,一题都没搞出来,这题搞了N久居然还是搞不出来,一直TLE,最后还是参考别人代码才领悟的,思路就这么简单, 就是不会转弯,看着模板却不会改,艹,真怀疑自己是不是个笨蛋题意:求 ...
- 2018 Multi-University Training Contest 10 CSGO(HDU - 6435)(最远曼哈顿距离)
有 n 种主武器,m 种副武器.每种武器有一个基础分数k种属性值 X[i] . 选出一种主武器 mw 和一种副武器 sw,使得两种武器的分数和 + 每个属性的差值尽量大.(参考下面的式子) 多维的最远 ...
- POJ-2926 Requirements 最远曼哈顿距离
题目链接:http://poj.org/problem?id=2926 题意:求5维空间的点集中的最远曼哈顿距离.. 降维处理,推荐2009武森<浅谈信息学竞赛中的“0”和“1”>以及&l ...
- Codeforces 491B. New York Hotel 最远曼哈顿距离
最远曼哈顿距离有两个性质: 1: 对每一个点(x,y) 分别计算 +x+y , -x+y , x-y , -x-y 然后统计每种组合的最大值就能够了, 不会对结果产生影响 2: 去掉绝对值 , 设 ...
随机推荐
- 初学JDBC,防SQL注入简单示例
在JDBC简单封装的基础上实现 public class UserDao{ public static void testGetUser(String userName) throws Excepti ...
- CSS 兼容 总结
1> margin加倍的问题 设置为float的div在ie下设置的margin会加倍.这是一个ie6都存在的bug. 解决方案是在这个div里面加上display:inline; 例如: &l ...
- iOS多线程介绍
一.线程概述 有些程序是一条直线,起点到终点:有些程序是一个圆,不断循环,直到将它切断.直线的如简单的Hello World,运行打印完,它的生命周期便结束了,像昙花一现那样:圆如操作系统,一直运行直 ...
- 转:this的用法
this指针的含义及其用法: 1. this指针是一个隐含于每一个成员函数中的特殊指针.它指向正在被该成员函数操作的那个对象.2. 当对一个对象调用成员函数时,编译程序先将对象的地址赋给this指针, ...
- malloc 函数到底做了什么?
请看下面的代码. 猜测结果是什么?编译通过吗? #include <stdio.h> #include <stdlib.h> int main() { ; char *ptr ...
- 交叉编译php5,、nginx、squid方法
本文为原创,转载请注明:http://www.cnblogs.com/tolimit/ 交叉编译php5 软件版本:php-5.4.27 依赖库:zlib,libxml2 交叉编译器:arm-hisi ...
- Ninth scrum meeting - 2015/11/3
今天课上老师询问了每个团队的进度,我们发现有好多团队都已经基本完成了, 距离预定的alpha版本开发完成时间也越来越近了,我们的工作也都在有条不紊的进行着.今天又出现了git pull时有冲突的情况, ...
- navicat连接oracle报错ORA-12737: Instant Client Light: unsupported server character set CHS16GBK”
原文如下http://blog.163.com/cp7618@yeah/blog/static/7023477720142154449893/?COLLCC=1318255100& 这个工具可 ...
- Python socket 详解
socket()函数用于根据指定的地址族.数据类型和协议来分配一个套接口的描述字及其所用的资源.如果协议protocol未指定(等于0),则使用缺省的连接方式. 对于使用一给定地址族的某一特定套接口, ...
- HDOJ 1864 最大报销额(01背包)
http://acm.hdu.edu.cn/showproblem.php?pid=1864 最大报销额 Time Limit: 1000/1000 MS (Java/Others) Memor ...