链接:https://codeforces.com/contest/1136/
A - Nastya Is Reading a Book - [二分]
#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; }
B - Nastya Is Playing Computer Games - [思维题]
题解:我只想说,这道思维题有点东西……
AC代码:
#include<bits/stdc++.h> using namespace std; int n,k; int main() { cin>>n>>k; cout<<3*n+min(n-k,k-1)<<endl; }
原文地址:https://www.cnblogs.com/dilthey/p/10540424.html
时间: 2024-11-01 21:54:45