POJ 2140 Herd Sums
http://poj.org/problem?id=2140
Description
Farmer John, who majored in mathematics in college and loves numbers, often looks for patterns. He has noticed that when he has exactly 15 cows in his herd, there are precisely four ways that the numbers on any set of one or more consecutive cows can add up to 15 (the same as the total number of cows). They are: 15, 7+8, 4+5+6, and 1+2+3+4+5.
When the number of cows in the herd is 10, the number of ways he can sum consecutive cows and get 10 drops to 2: namely 1+2+3+4 and 10.
Write a program that will compute the number of ways farmer John can sum the numbers on consecutive cows to equal N. Do not use precomputation to solve this problem.
Input
Output
Sample Input
15
Sample Output
4
ps:consecutive 连续地
水题.....一次过
//{头文件
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
//}头文件 double N; bool f(int n) //n为几个数组相连
{
double n0 = n,k = N / n0;
int t = k;
if( n% ){
if(t == k){
if(t - n/ > )return true;
}
}
else {
if( t * n + n/ == N){
if(t + - n/ >)return true;
}
}
return false;
} int main()
{
cin >> N;
int T = ;
for(int i = ; i < N/;i++){
if(f(i))T++;
}
cout << T <<endl;
//system("pause");
return ;
}
POJ 2140 Herd Sums的更多相关文章
- hdu 2715 Herd Sums
Herd Sums Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- POJ 3086 Triangular Sums (ZOJ 2773)
http://poj.org/problem?id=3086 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1773 让你计算两 ...
- POJ 2140
#include<iostream> #include<stdio.h> using namespace std; int main() { int num; int i; i ...
- Poj 2602 Superlong sums(大数相加)
一.Description The creators of a new programming language D++ have found out that whatever limit for ...
- 【转】POJ百道水题列表
以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...
- POJ解题经验交流
感谢范意凯.陈申奥.庞可.杭业晟.王飞飏.周俊豪.沈逸轩等同学的收集整理. 题号:1003 Hangover求1/2+1/3+...1/n的和,问需多少项的和能超过给定的值 类似于Zerojudg ...
- 算法之路 level 01 problem set
2992.357000 1000 A+B Problem1214.840000 1002 487-32791070.603000 1004 Financial Management880.192000 ...
- POJ 1503 Integer Inquiry(大数相加)
一.Description One of the first users of BIT's new supercomputer was Chip Diller. He extended his exp ...
- 转载:hdu 题目分类 (侵删)
转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...
随机推荐
- UVA10562 数据结构题目
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...
- VC编程命名方法
1.
- DOM之节点|属性
1.查询文档的一个或多个元素有如下方法 a. 用指定的id属性:(若一个文档中有两个相同的id,只会选择第一个;在低于IE8的IE中,getElementById()对匹配元素的ID不区分大小写,而且 ...
- hadoop调优之一:概述
hadoop集群性能低下的常见原因 (一)硬件环境 1.CPU/内存不足,或未充分利用 2.网络原因 3.磁盘原因 (二)map任务原因 1.输入文件中小文件过多,导致多次启动和停止JVM进程.可以设 ...
- Python基础第四天
必须掌握的内置函数 bytes() divmod() eval() exec() isinstance() range() 常用函数 1.数学相关 abs(x) abs()返回一个数字的绝对值.如果给 ...
- python 画正弦曲线
要画正弦曲线先设定一下x的取值范围,从0到2π.要用到numpy模块. numpy.pi 表示π numpy.arange( 0 , 2π ,0.01) 从0到2π,以0.01步进. 令 x=num ...
- Windows 下 pip和easy_install 的安装与使用
最简单的莫过于用vs 开发python 的程序,集成PTVS插件后,果然简单易用,调试也方便. 手工搭建的话: 官网:https://pypi.python.org/pypi/setuptools 主 ...
- Android高德地图自定义Markers的例子
下文为各位重点介绍关于Android高德地图自定义Markers的例子,希望这篇文章能够让各位理解到Android高德地图自定义Markers的方法. 之前的博客里说了地图的嵌入和定位,今天就说说在地 ...
- postgresql C/C++ API 接口
1,postgresql学习uri推荐 http://www.php100.com/manual/PostgreSQL8/ http://www.php100.com/manual/PostgreSQ ...
- c++中可以对类中私有成员中的静态变量初始化吗?
转载http://www.cnblogs.com/carbs/archive/2012/04/04/2431992.html 问题:我看的书上写的对私有部分的访问可以是公共部分的成员函数,也可以是友员 ...