Codeforces 1136 - A/B/C/D/E - (Done)

連接:https://codeforces.com/contest/1136/html


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 - [思惟題]

題解:我只想說,這道思惟題有點東西……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;
}

 


C - Nastya Is Transposing Matrices - [有趣的矩陣題]

 


D - Nastya Is Buying Lunch - [貪心+鏈表+map]

 


E - Nastya Hasn't Written a Legend - [線段樹+二分]

相關文章
相關標籤/搜索