zoukankan      html  css  js  c++  java
  • 抗击疫情 从我做起 训练赛五

    问题 I: Anti-Division(容斥原理)
    题目描述
    You are given four integers A, B, C, and D. Find the number of integers between A and B (inclusive) that can be evenly divided by neither C nor D.

    Constraints
    ·1≤A≤B≤1018
    ·1≤C,D≤109
    ·All values in input are integers.

    输入
    Input is given from Standard Input in the following format:

    A B C D

    输出
    Print the number of integers between A and B (inclusive) that can be evenly divided by neither C nor D.
    样例输入 Copy
    【样例1】
    4 9 2 3
    【样例2】
    10 40 6 8
    【样例3】
    314159265358979323 846264338327950288 419716939 937510582
    样例输出
    【样例1】
    2
    【样例2】
    23
    【样例3】
    532105071133627368
    提示
    样例1解释:5 and 7 satisfy the condition.

    #include <bits/stdc++.h>
    using namespace std;
    #define int long long
    int a,b,c,d;
    
    signed main(){
        ios::sync_with_stdio(0);
        cin >> a >> b >> c >> d;
        int cc = b / c - (a - 1) / c;//不能合并
        int dd = b / d - (a - 1)/ d;
        int ccdd = c * d / __gcd(c,d);//LCM
        int cd = b / ccdd- (a - 1) / ccdd;
        cout << (b - a + 1) - cc - dd + cd << endl;
        return 0;
    }
    

    题意 [a,b] 找出既不能整除c,也不能整除d的所有数字个数
    一看到1e18,心想:完了,这个题怎么解啊,怎么判断,然后掠过去做别的了,过会看榜的时候,这个题过的人挺多的,为什么我一点思路也没有,心情继续丧,直到结束,也没有想到这个题该怎么做,
    在这里插入图片描述
    相信看完这幅图之后,应该明白了

    问题 C: NH2014字符串

    题目描述
    小熊有一个由小写英文字母组成的字符串s = s1s2…sn。小熊想要计算s中有多少子串包含字符串“bear”,也就是找出满足字符串x(i, j)= sisi+1…sj 包含至少一个字符串“bear”的(i, j)对数(1≤i≤j≤n)。
    字符串x(i, j)包含字符串“bear”定义为存在一个整数k(i≤k≤j-3),满足sk=b,sk+1=e,sk+2=a,sk+3=r。
    请帮助小熊解决这个问题。

    输入
    输入共1行,包含一个非空字符串s。数据保证字符串s中只包含小写英文字母。
    输出
    输出共1行,包含一个整数,表示这个问题的答案。
    样例输入 Copy
    bebearar
    样例输出 Copy
    9
    提示
    符合条件的9对(i, j)为:(1,6),(1,7),(1,8),(2,6),(2,7),(2,8),(3,6),(3,7),(3,8)。

    对于50%的数据,1≤n≤200。
    对于100%的数据,1≤n≤3000。

    #include <bits/stdc++.h>
    #define int long long
    using namespace std;
    string str;
    int ans;
    
    signed main(){
        ios::sync_with_stdio(false);
        cin >> str;
        for (int i = str.size() - 4, l = str.size() - 3;i >= 0; i--){
            if (str[i] == 'b' && str[i + 1] == 'e' && str[i + 2] == 'a' && str[i + 3] == 'r')	l = i;
            ans += str.size() - l - 3;
        }
        cout << ans << endl;
        return 0;
    }
    
    
    
  • 相关阅读:
    Andorid手机振动器(Vibrator)的使用
    Log.i()的用法
    刀哥多线程现操作gcd-10-delay
    刀哥多线程全局队列gcd-09-global_queue
    刀哥多线程Barrier异步gcd-08-barrier_async
    刀哥多线程同步任务作用gcd-07-sync_task
    刀哥多线程之主队列gcd-06-main_queue
    刀哥多线程之并发队列gcd-05-dispatch_queue_concurrent
    刀哥多线程串行队列gcd-04-dispatch_queue_serial
    刀哥多线程之03GCD 常用代码
  • 原文地址:https://www.cnblogs.com/xcfxcf/p/12301578.html
Copyright © 2011-2022 走看看