AOJ2600 Koto Distance

Koto Distance | Aizu Online Judge

Introduction to Programming Introduction to Algorithms and Data Structures Library of Data Structures Library of Graph Algorithms Library of Computational Geometry Library of Dynamic Programming Library of Number Theory

X方向,Y方向それぞれに累積和を取る.X,Yのどちらかが埋まっていれば覆われている.

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
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#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 INF 1<<30
#define pb push_back
#define mp make_pair

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

int X[100005], Y[100005];

int main() {
  int n, W, H;
  cin >> n >> W >> H;

  memset(X, 0, sizeof(X));
  memset(Y, 0, sizeof(Y));

  rep(i, n) {
      int x, y, w;
      cin >> x >> y >> w;

      X[max(0, x-w)]++;
      X[min(W, x+w)]--;

      Y[max(0, y-w)]++;
      Y[min(H, y+w)]--;
  }

  REP(i, 1, 100005) {
      X[i] += X[i-1];
      Y[i] += Y[i-1];
  }

  bool a = true, b = true;
  REP(i, 0, W) {
      if(X[i] == 0) a = false;
  }

  REP(i, 0, H) {
      if(Y[i] == 0) b = false;
  }

  if(a || b) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}
Mar 22nd, 2016