#include <cstdio> #include <iostream> #include <algorithm> #include <cstring> #include <vector> #include <set> #include <map> #include <array> #include <random> #include <cmath> #include <list> #include <ctime> #include <sstream> #include <queue> #include <climits> #include <stack> #include <random> #include <bitset> #include <numeric> #include <cassert> using namespace std; typedef vector<int> vi; typedef pair<int,int> pii; typedef long long ll; #define rep(x, b, e) for(int x=(b); x<(e); ++x) #define trav(a, x) for(auto& a : x) #define ford(x, b, e) for(int x=((int)(b))-1; x>=(e); --x) #define all(c) c.begin(),c.end() #define sz(x) ((int)((x).size())) #define pb push_back #define st first #define nd second #define mp(x,y) make_pair(x,y) typedef short int sint; #define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " int P; bool inMask(int mask, int v) { return (mask & (1 << v)) > 0; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; scanf("%d", &n); vector<ll> a(n), r(n); rep(i, 0, n) { scanf("%lld %lld", &a[i], &r[i]); } set<int> possible; rep(mask, 0, (1 << n)) { queue<int> toBlow; int blown = mask; rep(i, 0, n) { if ((mask & (1 << i))) { toBlow.push(i); } } while (!toBlow.empty()) { int cur = toBlow.front(); toBlow.pop(); rep(i, 0, n) { if (inMask(blown, i)) { continue; } if (a[cur] - r[cur] <= a[i] && a[i] <= a[cur] + r[cur]) { blown |= (1 << i); toBlow.push(i); } } } possible.insert(blown); } printf("%d\n", sz(possible)); }
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 | #include <cstdio> #include <iostream> #include <algorithm> #include <cstring> #include <vector> #include <set> #include <map> #include <array> #include <random> #include <cmath> #include <list> #include <ctime> #include <sstream> #include <queue> #include <climits> #include <stack> #include <random> #include <bitset> #include <numeric> #include <cassert> using namespace std; typedef vector<int> vi; typedef pair<int,int> pii; typedef long long ll; #define rep(x, b, e) for(int x=(b); x<(e); ++x) #define trav(a, x) for(auto& a : x) #define ford(x, b, e) for(int x=((int)(b))-1; x>=(e); --x) #define all(c) c.begin(),c.end() #define sz(x) ((int)((x).size())) #define pb push_back #define st first #define nd second #define mp(x,y) make_pair(x,y) typedef short int sint; #define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " int P; bool inMask(int mask, int v) { return (mask & (1 << v)) > 0; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; scanf("%d", &n); vector<ll> a(n), r(n); rep(i, 0, n) { scanf("%lld %lld", &a[i], &r[i]); } set<int> possible; rep(mask, 0, (1 << n)) { queue<int> toBlow; int blown = mask; rep(i, 0, n) { if ((mask & (1 << i))) { toBlow.push(i); } } while (!toBlow.empty()) { int cur = toBlow.front(); toBlow.pop(); rep(i, 0, n) { if (inMask(blown, i)) { continue; } if (a[cur] - r[cur] <= a[i] && a[i] <= a[cur] + r[cur]) { blown |= (1 << i); toBlow.push(i); } } } possible.insert(blown); } printf("%d\n", sz(possible)); } |