http://poj.org/problem?id=2140

Description

The cows in farmer John's herd are numbered and branded with consecutive integers from 1 to N (1 <= N <= 10,000,000).  When the cows come to the barn for milking, they always come in sequential order from 1 to N.
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

* Line 1: A single integer: N

Output

* Line 1: A single integer that is the number of ways consecutive cow brands can sum to N.

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的更多相关文章

  1. hdu 2715 Herd Sums

    Herd Sums Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  2. POJ 3086 Triangular Sums (ZOJ 2773)

    http://poj.org/problem?id=3086 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1773 让你计算两 ...

  3. POJ 2140

    #include<iostream> #include<stdio.h> using namespace std; int main() { int num; int i; i ...

  4. Poj 2602 Superlong sums(大数相加)

    一.Description The creators of a new programming language D++ have found out that whatever limit for ...

  5. 【转】POJ百道水题列表

    以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...

  6. POJ解题经验交流

    感谢范意凯.陈申奥.庞可.杭业晟.王飞飏.周俊豪.沈逸轩等同学的收集整理.   题号:1003 Hangover求1/2+1/3+...1/n的和,问需多少项的和能超过给定的值 类似于Zerojudg ...

  7. 算法之路 level 01 problem set

    2992.357000 1000 A+B Problem1214.840000 1002 487-32791070.603000 1004 Financial Management880.192000 ...

  8. POJ 1503 Integer Inquiry(大数相加)

    一.Description One of the first users of BIT's new supercomputer was Chip Diller. He extended his exp ...

  9. 转载:hdu 题目分类 (侵删)

    转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...

随机推荐

  1. Java如何获取当前的jar包路径以及如何读取jar包中的资源

    写作业的时候要输出一个record.dat文件到jar包的同级目录,但是不知道怎么定位jar包的路径.百度到的方法不很靠谱,所以在这里记录一下. 一:使用类路径 String path = this. ...

  2. 【干货】.NET开发通用组件发布(三) 简易数据采集组件

    组件介绍和合作开发 http://www.cnblogs.com/MrHuo/p/MrHuoControls.html 简易数据采集组件 怎么说他是一个简易的数据采集组件呢?因为由于时间仓促,缺少从某 ...

  3. excel筛选两列值是否相同,如果相同返回第三列值

    见图:

  4. html 作业1

    <body bgcolor="#000000" topmargin="200px" leftmargin="200px" text=& ...

  5. LeetCode_Unique Binary Search Trees

    Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For examp ...

  6. PowerShell_零基础自学课程_9_高级主题:静态类和类的操作

    上次我们说到了,wmi对象和com组件,今天我们继续来看PS中对象的相关内容.主要说一下静态对象和对象的基本操作. 一.静态对象 在PS中有一类特殊的对象,我们不能同过这些类创建新的对象,这些类是不能 ...

  7. 图解SSL/TLS协议(转)

    本周,CloudFlare宣布,开始提供Keyless服务,即你把网站放到它们的CDN上,不用提供自己的私钥,也能使用SSL加密链接. 我看了CloudFlare的说明(这里和这里),突然意识到这是绝 ...

  8. java cglib动态代理原理及样例

     cglib动态代理: http://blog.csdn.net/xiaohai0504/article/details/6832990 一.原理 代理为控制要访问的目标对象提供了一种途径.当访问 ...

  9. DBA 经典面试题(4)

    1.如果信息采集管理系统(ICM)崩溃了怎么办?  答案:所有其他的管理器都会继续工作.ICM只会处理队列控制请求,意思是开启和关闭其他并发的管理器.    2.你如何加速打补丁的过程?    答案: ...

  10. JAVA中的正则表达式--待续

    1.关于“\”,在JAVA中的正则表达式中的不同: 在其他语言中"\\"表示为:我想要在正则表达式中插入一个普通的反斜杠: 在Java中“\\”表示为:我想要插入一个正则表达式反斜 ...