#include<bits/stdc++.h>
using namespace std;
set<int> s;
long long tab[105];
long long range[105];
bool odw[105];
void det(int x,int a)
{
odw[x] = true;
for(int y=0;y<a;y++)
if(!odw[y] && abs(tab[y] - tab[x]) <= range[x])
det(y,a);
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int a;
cin>>a;
for(int x=0;x<a;x++)
cin>>tab[x]>>range[x];
for(int x=0;x<(1<<a);x++)
{
int pom = x;
for(int y=0;y<a;y++)
{
if(pom&1)
det(y,a);
pom/=2;
}
for(int x=0;x<a;x++)
{
pom*=2;
pom+=odw[x];
odw[x] = false;
}
s.insert(pom);
}
cout<<s.size();
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 | #include<bits/stdc++.h> using namespace std; set<int> s; long long tab[105]; long long range[105]; bool odw[105]; void det(int x,int a) { odw[x] = true; for(int y=0;y<a;y++) if(!odw[y] && abs(tab[y] - tab[x]) <= range[x]) det(y,a); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int a; cin>>a; for(int x=0;x<a;x++) cin>>tab[x]>>range[x]; for(int x=0;x<(1<<a);x++) { int pom = x; for(int y=0;y<a;y++) { if(pom&1) det(y,a); pom/=2; } for(int x=0;x<a;x++) { pom*=2; pom+=odw[x]; odw[x] = false; } s.insert(pom); } cout<<s.size(); return 0; } |
English