#include <bits/stdc++.h> #define int long long #define mp make_pair #define pb push_back #define ld long double #define pii pair<int,int> #define sz(x) (int)x.size() #define piii pair<pii,pii> #define precise cout<<fixed<<setprecision(10) #define st first #define nd second #define ins insert #define vi vector<int> #define BOOST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0) using namespace std; const int MAX=1e3+5; const int MAX2=30; int a[MAX]; int r[MAX]; int lewy[MAX],prawy[MAX]; bitset<MAX2>pom[MAX]; int32_t main(){ BOOST; int n; cin>>n; for (int i=1;i<=n;i++){ cin>>a[i]>>r[i]; } for (int i=1;i<=n;i++){ set<int>xd; xd.clear(); xd.ins(i); while (true){ int nowe=0; for (auto it:xd){ for (int j=1;j<=n;j++){ if (abs(a[it]-a[j])<=r[it] && xd.find(j)==xd.end())xd.ins(j),nowe++; } } if (!nowe)break; } lewy[i]=*xd.begin(); prawy[i]=*xd.rbegin(); //cout<<"TERAZ "<<i<<" "<<lewy[i]<<" "<<prawy[i]<<"\n"; for (int j=lewy[i];j<=prawy[i];j++)pom[i][j]=true; } int ans=0; for (int msk=0;msk<(1<<n);msk++){ bitset<MAX2>probuj; probuj.reset(); for (int i=1;i<=n;i++){ if ((1<<(i-1))&msk)probuj|=pom[i]; } bool czy=true; for (int i=1;i<=n;i++){ bool xddd=(((1<<(i-1))&msk)>0); if (probuj[i]!=xddd){czy=false;break;} } if (czy)ans++; } cout<<ans; 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 64 65 | #include <bits/stdc++.h> #define int long long #define mp make_pair #define pb push_back #define ld long double #define pii pair<int,int> #define sz(x) (int)x.size() #define piii pair<pii,pii> #define precise cout<<fixed<<setprecision(10) #define st first #define nd second #define ins insert #define vi vector<int> #define BOOST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0) using namespace std; const int MAX=1e3+5; const int MAX2=30; int a[MAX]; int r[MAX]; int lewy[MAX],prawy[MAX]; bitset<MAX2>pom[MAX]; int32_t main(){ BOOST; int n; cin>>n; for (int i=1;i<=n;i++){ cin>>a[i]>>r[i]; } for (int i=1;i<=n;i++){ set<int>xd; xd.clear(); xd.ins(i); while (true){ int nowe=0; for (auto it:xd){ for (int j=1;j<=n;j++){ if (abs(a[it]-a[j])<=r[it] && xd.find(j)==xd.end())xd.ins(j),nowe++; } } if (!nowe)break; } lewy[i]=*xd.begin(); prawy[i]=*xd.rbegin(); //cout<<"TERAZ "<<i<<" "<<lewy[i]<<" "<<prawy[i]<<"\n"; for (int j=lewy[i];j<=prawy[i];j++)pom[i][j]=true; } int ans=0; for (int msk=0;msk<(1<<n);msk++){ bitset<MAX2>probuj; probuj.reset(); for (int i=1;i<=n;i++){ if ((1<<(i-1))&msk)probuj|=pom[i]; } bool czy=true; for (int i=1;i<=n;i++){ bool xddd=(((1<<(i-1))&msk)>0); if (probuj[i]!=xddd){czy=false;break;} } if (czy)ans++; } cout<<ans; return 0; } |