Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- //#include <bits/stdc++.h>
- #include <vector>
- using namespace std;
- int rastojanie(int a, int b) {
- return abs(a-b);
- }
- string levo_ili_desno(pair<int,int> platforma, pair<int,int> otsecka) {
- if(otsecka.first<platforma.first) {
- return "levo";
- }
- return "desno";
- }
- int main(){
- int N,L;
- pair<int,int> platforma;
- cin>>N>>L;
- vector<pair<int,int>> otsecka;
- platforma.first = 0;
- platforma.second = L;
- for(int i = 0; i<N; i++){
- int x,y;
- cin>>x>>y;
- otsecka.push_back(make_pair(x,y));
- }
- int brojac = 0;
- for(int i = 0; i<N; i++) {
- if(otsecka[i].first<platforma.first and otsecka[i].second>platforma.second) {
- continue;
- }
- if(otsecka[i].first>=platforma.first and otsecka[i].second<=platforma.second) {
- brojac++;
- }
- else {
- if(levo_ili_desno(platforma,otsecka[i])=="levo") {
- if(rastojanie(platforma.first,otsecka[i].second)>=rastojanie(platforma.first,otsecka[i].first)) {
- brojac++;
- platforma.first = otsecka[i].first;
- }
- }
- else {
- if(rastojanie(otsecka[i].first,platforma.second)>=rastojanie(otsecka[i].second,platforma.second)) {
- brojac++;
- platforma.second = otsecka[i].second;
- }
- }
- }
- }
- cout<<brojac;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement