zoukankan      html  css  js  c++  java
  • 小乐乐的组合数+

    题目描述

    小乐乐得知一周有7天之后就对7产生了兴趣。
    小乐乐得到了两堆数字数字时连续的。
    第一堆包含[1,n]n个数字,第二堆包含[1,m]m个数字。
    小乐乐想要从两堆中各挑选出一个整数x,y,使得x,y的和为7的倍数。

    请问小乐乐有多少种组合的方式。

    输入描述:

    输入整数n,m。(1<=n,m<=1e6)

    输出描述:

    输出满足的对数。
    示例1

    输入

    6 7

    输出

    6

    说明

    (1,6),(2,5),(3,4),(4,3),(5,2),(6,1)

    题意

      中文题意很简单,不做解释了。

    分析

      在[1,n]中找一个数加上[1,m]中的数,其实就是在[1,m]中的数一个一个拿出来,都加上[1,n]也就是最朴实的两层for循环枚举加和的状态。

      我们可以发现,对于一个[1,m]的数x,在分别加上[1,n]后,得到的是[x+1,x+m]一组连续的数,我们知道1~x+m中7的倍数是(x+m)/7,所以[x+1,x+m]中7的倍数就是(x+m)/7-x/7。

      所以枚举x求和就可以了。

    ///  author:Kissheart  ///
    #include<stdio.h>
    #include<algorithm>
    #include<iostream>
    #include<string.h>
    #include<vector>
    #include<stdlib.h>
    #include<math.h>
    #include<queue>
    #include<deque>
    #include<ctype.h>
    #include<map>
    #include<set>
    #include<stack>
    #include<string>
    #define INF 0x3f3f3f3f
    #define FAST_IO ios::sync_with_stdio(false)
    const double PI = acos(-1.0);
    const double eps = 1e-6;
    const int MAX=1e6+10;
    const int mod=1e9+7;
    typedef long long ll;
    using namespace std;
    #define gcd(a,b) __gcd(a,b)
    inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
    inline ll qpow(ll a,ll b){ll r=1,t=a; while(b){if(b&1)r=(r*t)%mod;b>>=1;t=(t*t)%mod;}return r;}
    inline ll inv1(ll b){return qpow(b,mod-2);}
    inline ll exgcd(ll a,ll b,ll &x,ll &y){if(!b){x=1;y=0;return a;}ll r=exgcd(b,a%b,y,x);y-=(a/b)*x;return r;}
    inline ll read(){ll x=0,f=1;char c=getchar();for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;for(;isdigit(c);c=getchar()) x=x*10+c-'0';return x*f;}
    //freopen( "in.txt" , "r" , stdin );
    //freopen( "data.txt" , "w" , stdout );
    ll n,m,x;
    ll sum=0;
    int main()
    {
        scanf("%lld%lld",&n,&m);
        for(ll i=1;i<=n;i++)
                sum+=(m+i)/7-i/7;
            printf("%lld
    ",sum);
        return 0;
    }
    View Code
  • 相关阅读:
    AJAX异步传输——以php文件传输为例
    js控制json生成菜单——自制菜单(一)
    vs2010中关于HTML控件与服务器控件分别和js函数混合使用的问题
    SQL数据库连接到服务器出错——无法连接到XXX
    PHP错误:Namespace declaration statement has to be the very first statement in the script
    【LeetCode】19. Remove Nth Node From End of List
    【LeetCode】14. Longest Common Prefix
    【LeetCode】38. Count and Say
    【LeetCode】242. Valid Anagram
    【LeetCode】387. First Unique Character in a String
  • 原文地址:https://www.cnblogs.com/Kissheart/p/10060666.html
Copyright © 2011-2022 走看看