1. 程式人生 > >Codeforces 1136 - A/B/C/D/E/F - (Undone)

Codeforces 1136 - A/B/C/D/E/F - (Undone)

test spa clu () int 二分 main con nbsp

鏈接: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;
}

Codeforces 1136 - A/B/C/D/E/F - (Undone)