Advertisement
Guest User

Heura na 40

a guest
Feb 21st, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int sr[1010];
  6. int pro[1010];
  7. bool wyl[1010];
  8. bool przec[1010][1010];
  9. vector<int> sasiady[1010];
  10. int ile_przecina[1010];
  11.  
  12. int main()
  13. {
  14. int n,a,b;
  15. scanf("%d",&n);
  16. for(int i=0;i<n;++i)
  17. {
  18. scanf("%d %d",&a,&b);
  19. sr[i]=a;
  20. pro[i]=b;
  21. }
  22. for(int i=0;i<n;++i)
  23. {
  24. for(int j=0;j<n;++j)
  25. {
  26. if(j!=i)
  27. {
  28. 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]) )
  29. {
  30. ile_przecina[i]++;
  31. sasiady[i].push_back(j);
  32. przec[i][j]=true;
  33. }
  34. }
  35. }
  36. }
  37.  
  38. int wyn=0;
  39.  
  40. for(int i=0;i<n;++i)
  41. {
  42. for(int j=0;j<n;++j)
  43. {
  44. if(przec[i][j]==true && wyl[i]==false && wyl[j]==false)
  45. {
  46. wyn++;
  47. if(ile_przecina[i]>=ile_przecina[j])
  48. {
  49. wyl[i]=true;
  50. for(int u=0;u<sasiady[i].size();++u)
  51. {
  52. ile_przecina[sasiady[i][u]]--;
  53. przec[i][sasiady[i][u]]=false;
  54. przec[sasiady[i][u]][i]=false;
  55. }
  56. }
  57. else
  58. {
  59. wyl[j]=true;
  60. for(int u=0;u<sasiady[j].size();++u)
  61. {
  62. ile_przecina[sasiady[j][u]]--;
  63. przec[j][sasiady[j][u]]=false;
  64. przec[sasiady[j][u]][j]=false;
  65. }
  66. }
  67. }
  68. }
  69. }
  70.  
  71. printf("%d\n",wyn);
  72.  
  73. return 0;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement