Advertisement
Josif_tepe

Untitled

Jan 25th, 2024
764
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.50 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.  
  21. int main(){
  22.     int N,L;
  23.     pair<int,int> platforma;
  24.     cin>>N>>L;
  25.     vector<pair<int,int>> otsecka;
  26.     platforma.first = 0;
  27.     platforma.second = L;
  28.    
  29.     for(int i = 0; i<N; i++){
  30.         int x,y;
  31.         cin>>x>>y;
  32.         otsecka.push_back(make_pair(x,y));
  33.     }
  34.  
  35.     int brojac = 0;
  36.  
  37.     for(int i = 0; i<N; i++) {
  38.  
  39.  
  40.         if(otsecka[i].first<platforma.first and otsecka[i].second>platforma.second) {
  41.            continue;
  42.         }
  43.         if(otsecka[i].first>=platforma.first and otsecka[i].second<=platforma.second) {
  44.             brojac++;
  45.         }
  46.         else {
  47.             if(levo_ili_desno(platforma,otsecka[i])=="levo") {
  48.                 if(rastojanie(platforma.first,otsecka[i].second)>=rastojanie(platforma.first,otsecka[i].first)) {
  49.                     brojac++;
  50.                     platforma.first = otsecka[i].first;
  51.                 }
  52.             }
  53.             else {
  54.                 if(rastojanie(otsecka[i].first,platforma.second)>=rastojanie(otsecka[i].second,platforma.second)) {
  55.                     brojac++;
  56.                     platforma.second = otsecka[i].second;
  57.                 }
  58.             }
  59.         }
  60.     }
  61.     cout<<brojac;
  62.  
  63. }
  64.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement