HDU 4666 Hyperspace

Hyperspace

Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 136    Accepted Submission(s): 66


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
 

Source
 

Recommend
zhuyuanchen520
 
题意: 有Q个操作。 没次操作会增加一个点, 或者删除一个点。 每次输出点集的最大曼哈顿距离。

思路: STL应用
不知道什么原理,师兄说的。
一维就是  Max (x) - Min(x)
就是对于 二维的 x - y   和 x + y 做两个集合。 答案肯定会在  Max( x - y) -  Min( x - y)  或者 是  Max(x + y)  -  Min(x + y)
而三维就是 Max(x + y + z) - Min(x + y + z)  或者是 Max(x + y - z)  - Min(x + y - z) 略。
就是  a +- b +- c +- d +- e
2 ^ (k - 1)个集合里。
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
using namespace std;

//

const int V = 60000 + 50;
const int inf = 0x7fffffff;
int n, k;
int main() {
    int i, j, q;
    while(~scanf("%d%d", &n, &k)) {
        multiset<int> s[20];
        map<int, int> m[20];
        for(i = 1; i <= n; ++i) {
            int op;
            scanf("%d", &op);
            if(op == 0) {
                int po[10];
                for(j = 0; j < k; ++j)
                    scanf("%d", &po[j]);
                for(j = 0; j < (1 << (k - 1)); ++j) {
                    int sum = po[0];
                    for(q = 0; q < k - 1; ++q) {
                        if(j & (1 << q))
                            sum -= po[q + 1];
                        else
                            sum += po[q + 1];
                    }
                    s[j].insert(sum);
                    m[j][i] = sum;
                }
            }
            else {
                int temp;
                scanf("%d", &temp);
                for(j = 0; j < (1 << (k - 1)); ++j) {
                    if(m[j].size() > 0) {
                        s[j].erase(s[j].find(m[j][temp]));
                        m[j].erase(temp);
                    }
                }
            }
            int Max = 0;
            for(j = 0; j < (1 << (k - 1)); ++j) {
                if(s[j].size() > 0) {
                    multiset<int>::iterator fi = s[j].begin();
                    multiset<int>::iterator se = s[j].end();
                    se--;
                    Max = max(Max, *se - *fi);
                }
            }
            printf("%d\n", Max);
        }
    }
}


展开阅读全文

Hyperspace

06-25

Problem DescriptionnHyperspace ,A Euclidean space of dimension greater than three (the original meaning of the word hyperspace, common in late nineteenth century British books, sometimes used in paranormal context, but which has become rarer since then). Minkowski space, a concept, often referred to by science fiction writers as hyperspace that refers to the four-dimensional space-time of special relativity.n nHere we define a “Hyperspace” as a set of points in three-dimensional space. We define a function to describe its “Hyperspace Value”n nEvery vi (0<=i<=k) could be describe in three-dimensional reference system, say v0 (1, 2, 3)nFor the following question, we will have to deal with the “Hyperspaces”, you may assume that the number of “Hyperspace” is always no larger than 100.nAs we say above, we give every “Hyperspace” an “ID” to identify it.nIf you want to connect two points in two different “Hyperspaces”, it will cost you F to build the connection. F can be defined as the following expression:nnIn addition, you can only create at most one connection between any two “Hyperspaces”.nIf you want to connect two points in the same “Hyperspaces” whose “ID” is k, it will cost you G to build the connection. G can be defined as the following expression:nnHere nnNow your task is quite easy. nAekdyCoin gives you n “Hyperspaces”.nThen he gives you information about all the points in the “Hyperspaces”nNow he wants to know the minimal cost to connect all the points in all “Hyperspaces”nnyou have to ensure that any two different points in the same "Hyperspace" could be connected directly or indirectly by the connections you build in this "Hyperspace".n nnInputnThe input consists of several test cases.nIn the first line there is an integer n (1<=n<=100), indicating the number of “Hyperspaces”nThen follow an integer m (1<=m<=100000) nYou can assume that the number of different points in every “Hyperspace” is always no larger than 100.nThe next m lines contain the descriptions of all the pointsnAll the descriptions are given in the following format x,y,z,idnIndicating the point (x,y,z) belongs to the id “Hyperspace”nid is an integer.nx,y,z are all real number with at most four fractional digits.n-10000<=x,y,z<=10000,1<=id<=nn nnOutputnFor each test case, output the minimal cost on a single line.nPlease round it to four fractional digits.n nnSample Inputn1n2n1 2 1 1n1 3 1 1n nnSample Outputn1.0000 问答

Hyperspace Travel

12-03

Problem DescriptionnTraveling through hyperspace is a risky thing, considering the fact that there are many stars, asteroids, (and possibly black holes!) out in the galaxy, and without careful planning, it’s so easy to end up thousands of light-years from your planned destination. Therefore people who don’t like uncertainty tend to avoid hyperspace traveling. However, as we need to travel through an unknown sector to attend the ACM/ICPC world final in the year 3007, and you’re the most experienced navigator and programmer we can find, it is unfortunately your responsibility to plan a journey that will lead us across the sector.nnIt is know that there are several strange asteroids in the sector – every one of them is generating gravity anomaly in a circular area with a fixed radius around the asteroid. One particular position’s abnormality value is equal to the number of asteroids affecting that position. nnYou decided that you will follow one simple rule during your travel – that is, you will always fly your ship along the gravity range boundary of one or more asteroids. Nevertheless, the possibility of failure remains due to the unpredictable nature of gravity anomaly, therefore you also want to minimize the absolute difference between the maximum abnormality value and the minimum abnormality value on your flight path. For simplicity, you can assume that all asteroids (as well as your flight path) will be on the plane Z = 0. Can you find the minimum absolute value with the help of your computer? n nnInputnThere are multiple test cases in the input file. Each test case starts with one integer N (2 <= N <= 30), the number of asteroids in the sector, followed by four real numbers, Sx, Sy, Tx, Ty, representing the x-coordinate and y-coordinate of your current position and your destination. Each of the following N lines consists of three real numbers X, Y and R (R >= 1), indicating that there is an asteroid at position (X, Y) with gravity range R.nnThere is a blank line after each test case. N = 0 indicates the end of input file and should not be processed by your program. nnIt is guaranteed that the input data is always legal, i.e. both your starting position and your destination are on the boundary of one or more asteroids, no two asteroids will have the same position, every real number in the input file has at most three digits after the decimal point, and the absolute value of any real number does not exceed 10000.nn nnOutputnFor each test case, output one integer on one separate line as requested. If there is no way for you to reach the destination by only flying along asteroids’ gravity range boundaries, output -1 instead.nn nnSample Inputn2n-1.000 0.000 1.000 0.000n0.000 0.000 1.000n1.000 0.000 1.000nn2 n-1.000 0.000 5.000 0.000n-1.000 -1.000 1.000n4.000 0.000 1.000nn0n nnSample OutputnCase 1: 1nCase 2: -1n 问答

没有更多推荐了,返回首页