Advertisement
thesonpb

lật sách

Mar 30th, 2020
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.41 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int main(){
  4.     int n, p;
  5.     cin >> n >> p;
  6.     if((p-1)<(n-p)) {
  7.         if(p%2 != 0) cout<<(p-1)/2;
  8.         else cout<<p/2;
  9.     }
  10.     else {
  11.         if(n%2 != 0){
  12.             if(p%2 == 0) cout << (n-p-1)/2;
  13.             else cout<<(n-p+1)/2;
  14.         }
  15.         else{
  16.             if(p%2 == 0) cout << (n-p)/2;
  17.             else cout<<(n-p+1)/2;
  18.         }
  19.     }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement