zoukankan      html  css  js  c++  java
  • 【C++竞赛 H】The sum problem

    Time Limit: 1s Memory Limit: 32MB
    问题描述
    Given a sequence 1,2,3,…,N, your job is to calculate the number of sub-sequences that the sum of the sub-sequence is M.
    输入描述
    The first line contains a single integer T(1≤T≤10), indicating the number of test cases. Each case contains two integers N,M(1≤N,M≤1000).
    输出描述
    For each case, print a number in a line.
    输入样例
    2
    20 10
    50 30
    输出样例
    2
    4
    样例解释
    For the first case: the sum of sub-sequence [1, 4] and [10, 10] is 10.
    【题目链接】:

    【题解】

    傻逼题

    【完整代码】

    #include <bits/stdc++.h>
    
    using namespace std;
    
    
    int main()
    {
        freopen("H.in","r",stdin);
        freopen("H.out","w",stdout);
    
        int t;cin>>t;
        while(t--)
        {
            int n,m;
            cin>>n>>m;
            int ans=0;
            for(int i=1;i<=n;++i)
            {
                int sum=0;
                for(int j=i;j<=n;++j)
                {
                    sum+=j;
                    if(sum==m)
                        ans++;
                    else if(sum>m)
                        break;
                }
            }
            cout<<ans<<endl;
        }
        return 0;
    }
    
  • 相关阅读:
    【瞎口胡】基础数学 1 快速幂 整除 最大公约数
    【瞎口胡】二分图
    Windos下使用Redis
    VUE的踩坑日记(1)
    公告
    [维度打击]最大连续子序列
    常用函数
    树状数组
    高精度封装
    T4 模板之 单个文件
  • 原文地址:https://www.cnblogs.com/AWCXV/p/7626869.html
Copyright © 2011-2022 走看看