Advertisement
Josif_tepe

Untitled

Jan 25th, 2024
761
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.80 KB | None | 0 0
  1. #include <iostream>
  2. //#include <bits/stdc++.h>
  3. #include <vector>
  4. using namespace std;
  5.  
  6. int rastojanie(int a, int b) {
  7.     return abs(a-b);
  8. }
  9.  
  10. string levo_ili_desno(pair<int,int> platforma, pair<int,int> otsecka) {
  11.  
  12.     if(otsecka.first<platforma.first) {
  13.         return "levo";
  14.     }
  15.  
  16.     return "desno";
  17.  
  18.  
  19. }
  20. bool dali_moze(pair<int, int> otsecka, pair<int, int> platforma) {
  21.    
  22.     if(otsecka.first<platforma.first and otsecka.second>platforma.second) {
  23.         return false;
  24.     }
  25.     if(otsecka.first>=platforma.first and otsecka.second<=platforma.second) {
  26.         return true;
  27.     }
  28.    
  29.     if(levo_ili_desno(platforma,otsecka)=="levo") {
  30.             if(rastojanie(platforma.first,otsecka.second)>=rastojanie(platforma.first,otsecka.first)) {
  31.                 return true;
  32.                
  33.             }
  34.         }
  35.         else {
  36.             if(rastojanie(otsecka.first,platforma.second)>=rastojanie(otsecka.second,platforma.second)) {
  37.                 return true;
  38.                
  39.             }
  40.         }
  41.     return false;
  42.  
  43. }
  44. int main(){
  45.     int N,L;
  46.     pair<int,int> platforma;
  47.     cin>>N>>L;
  48.     vector<pair<int,int>> otsecka;
  49.     platforma.first = 0;
  50.     platforma.second = L;
  51.    
  52.     for(int i = 0; i<N; i++){
  53.         int x,y;
  54.         cin>>x>>y;
  55.         otsecka.push_back(make_pair(x,y));
  56.     }
  57.  
  58.     int brojac = 0;
  59.  
  60.     for(int i = 0; i<N; i++) {
  61.         for(int j = 0; j < N; j++) {
  62.             if(otsecka[j].first > -5000 and dali_moze(otsecka[j], platforma)) {
  63.                 brojac++;
  64.                 platforma.first = min(platforma.first, otsecka[j].first);
  65.                 platforma.second = max(platforma.second, otsecka[j].second);
  66.                
  67.                 otsecka[j].first = -5000;
  68.             }
  69.         }
  70.     }
  71.    
  72.     cout<<brojac;
  73.  
  74. }
  75.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement