【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;
}
【C++竞赛 H】The sum problem的更多相关文章
- 2018 ACMICPC上海大都会赛重现赛 H - A Simple Problem with Integers (线段树,循环节)
2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 H - A Simple Problem with Integers (线段树,循环节) 链接:https://ac.nowcoder.co ...
- HDu 1001 Sum Problem 分类: ACM 2015-06-19 23:38 12人阅读 评论(0) 收藏
Sum Problem Time Limit: 1000/500 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...
- HDU 2058:The sum problem(数学)
The sum problem Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- Problem-1001:Sum Problem
Sum Problem Sample code : #include <stdio.h> int main() { int i,n; int sum; while(scanf(" ...
- NYOJ 927 The partial sum problem 【DFS】+【剪枝】
The partial sum problem 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描写叙述 One day,Tom's girlfriend give him a ...
- summary of k Sum problem and solutions in leetcode
I found summary of k Sum problem and solutions in leetcode on the Internet. http://www.sigmainfy.com ...
- Subset sum problem
https://en.wikipedia.org/wiki/Subset_sum_problem In computer science, the subset sum problem is an i ...
- HD2058The sum problem
The sum problem Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tot ...
- Maxmum subsequence sum problem
We have a lot of ways to solve the maximum subsequence sum problem, but different ways take differen ...
- HDU 2058 The sum problem(枚举)
The sum problem Problem Description Given a sequence 1,2,3,......N, your job is to calculate all the ...
随机推荐
- php学习笔记5
PHP 常量 常量值被定义后,在脚本的其他任何地方都不能被改变. 一个常量由英文字母.下划线.和数字组成,但数字不能作为首字母出现. (常量名不需要加 $ 修饰符). 注意: 常量在整个脚本中都可以使 ...
- Keil 编译环境之在线仿真调试问题
一.问题现象: 这几天刚开始上手STM32,使用Keil 环境进行编程,然后使用ULINK2进行在线仿真,在按键处理函数程序中设置断点,却发现按了按键程序没有停在设置的断点,程序正常运行,如下图所示, ...
- [NPM] Update published npm packages using np
When we want to update our package we need to do a few things: pull latest from our git remote, bump ...
- Java基础学习总结(40)——Java程序员最常用的8个Java日志框架
作为一名Java程序员,我们开发了很多Java应用程序,包括桌面应用.WEB应用以及移动应用.然而日志系统是一个成熟Java应用所必不可少的,在开发和调试阶段,日志可以帮助我们更好更快地定位bug:在 ...
- 洛谷 P1657 选书
P1657 选书 题目描述 学校放寒假时,信息学奥赛辅导老师有1,2,3……x本书,要分给参加培训的x个人,每人只能选一本书,但是每人有两本喜欢的书.老师事先让每个人将自己喜欢的书填写在一张表上.然后 ...
- 电脑c盘清理
https://www.cnblogs.com/btchenguang/archive/2012/01/20/2328320.html
- 细说GCD
http://blog.csdn.net/hsf_study/article/details/51637453
- SpringMVC响应Ajax请求(@Responsebody注解返回页面)
项目需求描述:page1中的ajax请求Controller,Controller负责将service返回的数据填充到page2中,并将page2整个页面返回到page1中ajax的回调函数. 一句话 ...
- Oracle 排序问题(null带来的)
null 导致排序有问题, 对于数字的,一定要用nvl来解决.
- Android 自己定义主菜单
本文介绍一个超简单的自己定义主菜单.效果例如以下: 原理:事实上就是对原生的Dialog的一个简单的封装.并加上显示和隐藏的动画效果.再给控件加上回调事件. TestDialog.java publi ...