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. ...
随机推荐
- Python爬虫——抓取糗百段子
在别人博客里学习的 抓取糗百段子,由于糗百不断的更新,代码需要改正. 抓取网页:http://www.qiushibaike.com/hot/page/1 修改后的代码如下: # -*- coding ...
- FCKeditor插件开发实例:uploadify多文件上传插件
FCKeditor是一个专门使用在网页上属于开放源代码的所见即所得文字编辑器.它志于轻量化,不需要太复杂的安装步骤即可使用.它可和PHP.JavaScript.ASP.ASP.NET.ColdFusi ...
- destoon实现底部添加你是第几位访问者的方法
经常会看到一些网站有类似“您是第位访客”字样的计数统计,这里我们来实现把这个统计功能添加到destoon的底部,显示“你是第几问访问者”的效果.此处的计数器与网站流量统计有区别,记录的是刷新次数,并不 ...
- 'ascii' codec can't decode byte 0xef in position 0: ordinal not in range(128)——引用
在Django视图函数中经常出现类似于'ascii' codec can't decode byte 0xef in position 0: ordinal not in range(128)的错误. ...
- 收集点小文,讲CGI,FASTCGI,PHP-CGI,PHP-FPM之间通透点的文章
http://blog.csdn.net/meegomeego/article/details/36180343 http://www.opsers.org/linux-home/server/php ...
- mysql----用户root被删除或忘记root密码的解决方案
修改文件my.cnf,可用VIM打开,如:sudo vim /etc/my.cnf 在[mysqld]下加上一行: skip-grant-tables 保存文件,然后重启mysqld程序:sudo s ...
- C++默认构造函数的一点说明
大多数C++书籍都说在我们没有自己定义构造函数的时候,编译器会自动生成默认构造函数.其实这句话我一直也是 深信不疑.但是最近看了一些资料让我有了一点新的认识. 其实我觉得大多数C++书籍之所以这样描述 ...
- c、c++知识点
一. (1)在linux下类似uint8_t这样的文件定义在头文件<stdint.h>里面 (2)截取了stdint.h头文件里的一些常用部分 二.c++中c_str()用法 函数返回 ...
- Git版本控制与工作流详解
这篇文章是针对git版本控制和工作流的总结,如果有些朋友之前还没使用过git,对git的基本概念和命令不是很熟悉,可以从以下基本教程入手: 专为设计师而写的GitHub快速入门教程 git – 简明指 ...
- Ubuntu 启动器/快捷方式/ 制作 (Eclipse为例)
首先,在路径/usr/share/applications/,中创建eclipse.desktop(如果没有的话) sudo touch /usr/share/applications/eclipse ...