連接:https://codeforces.com/contest/1136/html
#include<bits/stdc++.h> using namespace std; const int maxn=105; int n,l[maxn],r[maxn],k; int srch(int x) { int L=1, R=n; while(L<R) { int M=(L+R)>>1; if(l[M]<=x && x<=r[M]) return M; else if(x<l[M]) R=M-1; else L=M+1; } return L; } int main() { ios::sync_with_stdio(0); cin.tie(0), cout.tie(0); cin>>n; for(int i=1;i<=n;i++) cin>>l[i]>>r[i]; cin>>k; cout<<n-srch(k)+1<<endl; }
題解:我只想說,這道思惟題有點東西……ios
AC代碼:c++
#include<bits/stdc++.h> using namespace std; int n,k; int main() { cin>>n>>k; cout<<3*n+min(n-k,k-1)<<endl; }