Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int sr[1010];
- int pro[1010];
- bool wyl[1010];
- bool przec[1010][1010];
- vector<int> sasiady[1010];
- int ile_przecina[1010];
- int main()
- {
- int n,a,b;
- scanf("%d",&n);
- for(int i=0;i<n;++i)
- {
- scanf("%d %d",&a,&b);
- sr[i]=a;
- pro[i]=b;
- }
- for(int i=0;i<n;++i)
- {
- for(int j=0;j<n;++j)
- {
- if(j!=i)
- {
- if( abs(sr[i]-sr[j])<pro[i]+pro[j] && abs(sr[i]-sr[j])+min(pro[i],pro[j])>max(pro[i],pro[j]) )
- {
- ile_przecina[i]++;
- sasiady[i].push_back(j);
- przec[i][j]=true;
- }
- }
- }
- }
- int wyn=0;
- for(int i=0;i<n;++i)
- {
- for(int j=0;j<n;++j)
- {
- if(przec[i][j]==true && wyl[i]==false && wyl[j]==false)
- {
- wyn++;
- if(ile_przecina[i]>=ile_przecina[j])
- {
- wyl[i]=true;
- for(int u=0;u<sasiady[i].size();++u)
- {
- ile_przecina[sasiady[i][u]]--;
- przec[i][sasiady[i][u]]=false;
- przec[sasiady[i][u]][i]=false;
- }
- }
- else
- {
- wyl[j]=true;
- for(int u=0;u<sasiady[j].size();++u)
- {
- ile_przecina[sasiady[j][u]]--;
- przec[j][sasiady[j][u]]=false;
- przec[sasiady[j][u]][j]=false;
- }
- }
- }
- }
- }
- printf("%d\n",wyn);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement