zoukankan      html  css  js  c++  java
  • 思维

    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;
    }
  • 相关阅读:
    渲染你刚刚上传的图片,再进行二次上传
    详情页需要显示图片
    上传图片
    毛利率保留俩位小数
    去除input的前后的空格
    vue下载模板、导出excle
    如何从一个对象里面拿数据
    登录注册
    ajax发送请求的数据类型
    WampServer修改MySQL密码
  • 原文地址:https://www.cnblogs.com/bhd123/p/9762177.html
Copyright © 2011-2022 走看看