#include <iostream> #include <algorithm> #include <cmath> #include <vector> #include <string> #include <map> #include <unordered_map> #include <set> #include <unordered_set> #include <queue> #include <deque> #include <climits> using namespace std; void input(int &n, vector<int> &pos, vector<int> &dist, vector<unordered_set<int>> &range) { int a, r; cin >> n; range.resize(n); for (int i = 0; i < n; i++) { cin >> a >> r; pos.push_back(a); dist.push_back(r); } for (int i = 0; i < n; i++) { int left = pos[i] - dist[i], right = pos[i] + dist[i]; for (int j = 0; j < n; j++) { if (left <= pos[j] && pos[j] <= right) { range[i].insert(j); // if (j < i) for (int x : range[j]) range[i].insert(x); } } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i == j) continue; if (range[j].count(i) > 0) { for (int x : range[i]) range[j].insert(x); } } } } void solve (int curr, vector<unordered_set<int>> &range, set<int> res, set<set<int>> &result) { if (curr == range.size()) return; solve(curr + 1, range, res, result); for (int x : range[curr]) res.insert(x); result.insert(res); solve(curr + 1, range, res, result); } int main() { int n; vector<int> pos, dist; vector<unordered_set<int>> range; input(n, pos, dist, range); set<set<int>> result; solve(0, range, {}, result); cout << result.size() + 1 << "\n"; // for (auto se : result) { // cout << "#1 = {"; // for (int x : se) cout << x << ", "; // cout << "\n"; // } return 0; }
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 | #include <iostream> #include <algorithm> #include <cmath> #include <vector> #include <string> #include <map> #include <unordered_map> #include <set> #include <unordered_set> #include <queue> #include <deque> #include <climits> using namespace std; void input(int &n, vector<int> &pos, vector<int> &dist, vector<unordered_set<int>> &range) { int a, r; cin >> n; range.resize(n); for (int i = 0; i < n; i++) { cin >> a >> r; pos.push_back(a); dist.push_back(r); } for (int i = 0; i < n; i++) { int left = pos[i] - dist[i], right = pos[i] + dist[i]; for (int j = 0; j < n; j++) { if (left <= pos[j] && pos[j] <= right) { range[i].insert(j); // if (j < i) for (int x : range[j]) range[i].insert(x); } } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i == j) continue; if (range[j].count(i) > 0) { for (int x : range[i]) range[j].insert(x); } } } } void solve (int curr, vector<unordered_set<int>> &range, set<int> res, set<set<int>> &result) { if (curr == range.size()) return; solve(curr + 1, range, res, result); for (int x : range[curr]) res.insert(x); result.insert(res); solve(curr + 1, range, res, result); } int main() { int n; vector<int> pos, dist; vector<unordered_set<int>> range; input(n, pos, dist, range); set<set<int>> result; solve(0, range, {}, result); cout << result.size() + 1 << "\n"; // for (auto se : result) { // cout << "#1 = {"; // for (int x : se) cout << x << ", "; // cout << "\n"; // } return 0; } |