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;
    }
  • 相关阅读:
    AndroidUI组件之ListView小技巧
    iframe属性參数
    Applet 数字签名技术全然攻略
    SoftReference
    递归算法浅谈
    VS2010 打包生成exe文件后 执行安装文件出现 TODO:&lt;文件说明&gt;已停止工作并已关闭
    创建新的Cocos2dx 3.0项目并解决一些编译问题
    ORACLE触发器具体解释
    SRM 624 D2L3: GameOfSegments, 博弈论,Sprague–Grundy theorem,Nimber
    cidaemon.exe进程cpu占用率高及关闭cidaemon.exe进程方法
  • 原文地址:https://www.cnblogs.com/bhd123/p/9762177.html
Copyright © 2011-2022 走看看