SRM312 D1E-D2M ParallelepipedUnion

TopCoder Statistics - Problem Statement

This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.

二つの直方体が与えられる.重なりも含めて何個もブロックになるかを求める.座標が$1 \sim 100$までしか無いので,配列を取って愚直に数える.

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define INF 1<<30
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

vector<string> split(const string &str, char delim) {
  vector<string> res;
  size_t current = 0, found;
  while((found = str.find_first_of(delim, current)) != string::npos) {
      res.push_back(string(str, current, found - current));
      current = found + 1;
  }
  res.push_back(string(str, current, str.size() - current));
  return res;
}

bool flag[105][105][105];

class ParallelepipedUnion {

    public:

    int getVolume(vector <string> parallelepipeds) {
      vector<string> a = split(parallelepipeds[0], ' ');
      vector<string> b = split(parallelepipeds[1], ' ');

      int n = a.size();
      vector<int> v1(n), v2(n);
      rep(i, n) {
          int x;
          stringstream ss;
          ss << a[i];
          ss >> x;
          v1[i] = x;
      }

      rep(i, n) {
          int x;
          stringstream ss;
          ss << b[i];
          ss >> x;
          v2[i] = x;
      }

      memset(flag, 0, sizeof(flag));

      REP(i, v1[0], v1[3]) {
          REP(j, v1[1], v1[4]) {
              REP(k, v1[2], v1[5]) {
                  flag[i][j][k] = true;
              }
          }
      }

      REP(i, v2[0], v2[3]) {
          REP(j, v2[1], v2[4]) {
              REP(k, v2[2], v2[5]) {
                  flag[i][j][k] = true;
              }
          }
      }

      int cnt = 0;
      rep(i, 105) {
          rep(j, 105) {
              rep(k, 105) {
                  cnt += flag[i][j][k];
              }
          }
      }

      return cnt;

    }
};
Sep 30th, 2016