• 思维


    codeforces 714 A

    Today an outstanding event is going to happen in the forest — hedgehog Filya will come to his old fried Sonya!

    Sonya is an owl and she sleeps during the day and stay awake from minute l1 to minute r1 inclusive. Also, during the minute k she prinks and is unavailable for Filya.

    Filya works a lot and he plans to visit Sonya from minute l2 to minute r2 inclusive.

    Calculate the number of minutes they will be able to spend together.

    The only line of the input contains integers l1r1l2r2 and k (1 ≤ l1, r1, l2, r2, k ≤ 1018l1 ≤ r1l2 ≤ r2), providing the segments of time for Sonya and Filya and the moment of time when Sonya prinks.

    Input
    1 10 9 20 1
    Output
    2
    Input
    1 100 50 200 75
    Output
    50

    题意:给你两个段 1--10 9--20。 求重合的多少,并且如果e在重合的范围内,就再去一。
    重合的段,即左端取大的,右边取小的。
    #include <iostream>
    #include<algorithm>
    #include<cstdio>
    typedef long long ll;
    using namespace std;
    int main()
    {
        ll a,b,c,d,e,ans;
        scanf("%lld %lld %lld %lld %lld",&a,&b,&c,&d,&e);
        ll a1=max(a,c);
        ll b1=min(b,d);
        if(b1>=a1)
        {
            ans=b1-a1+1;
            if(a1<=e&&e<=b1)
                ans-=1; 
            printf("%lld
    ",ans);
        }
        else
            printf("0
    ");
    
        
    
    
    
        return 0;
    }

    codeforces 719 b

    题意:给你一个只有r 和b构成的串,问最少改变几次能使串变成rbrbrbr  或者brbrbr

    1:单纯改变这个字符,例如:把b改成r;

    2:交换任意位置的 r和b;

    Input
    5
    rbbrr
    Output
    1
    Input
    5
    bbbbb
    Output
    2
    Input
    3
    rbr
    Output
    0
    #include <iostream>
    #include<cstdio>
    #include<algorithm>
    using namespace std;
    typedef long long ll;
    int main()
    {
        char a[100010];
        ll n,i,r1=0,b1=0,r2=0,b2=0;
        scanf("%lld",&n);
        scanf("%s",a);
        for(i=0;i<=n-1;i++)
        {
            if(a[i]=='r'&&i%2!=0)
            r1++;
            if(a[i]=='b'&&i%2==0)
                b2++;
            if(a[i]=='r'&&i%2==0)
                r2++;
            if(a[i]=='b'&&i%2!=0)
                b1++;
        }
        printf("%lld
    ",min(max(r1,b2),max(r2,b1)));
        return 0;
    }
  • 相关阅读:
    blocksit.js插件瀑布流
    防止点浏览器返回按钮,返回上一页的JS方法
    jquery 换肤功能
    HTML5获取地理位置
    百度api定位
    网站如何做到完全不需要使用jQuery
    让网页变成灰色代码
    利用html标签限制搜索引擎对网站的抓取收录
    高清ICON SVG解决方案
    加载动画
  • 原文地址:https://www.cnblogs.com/bhd123/p/9762177.html
Copyright © 2020-2023  润新知