hdu 2715 Herd Sums
Herd Sums
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 772    Accepted Submission(s): 375
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.
根据等差数列求和公式S=(a1+an)*n/2和末项公式an=a1+(n-1)*d(d位公差)得a1=(2*s+n-n*n)/2/n;得出求a1的公式然后对所有的n(n为项数)进行枚举,得出结果
2*s=(2*a1+n-1)*n所以n为偶数或者(2*a1+n-1)为偶数且a1不等于0
#include<stdio.h>
#include<string.h>
#include<math.h>
int main()
{
int n,m,j,i;
while(scanf("%d",&n)!=EOF)
{
int ans=sqrt(2*n);
int ant=0;
for(i=1;i<=ans;i++)
{
m=(2*n+i-i*i)/2/i;
if(2*m*i+i*i-i==2*n&&m>0&&(i%2==0||(2*m+i-1)%2==0))
ant++;
}
printf("%d\n",ant);
}
return 0;
}
hdu 2715 Herd Sums的更多相关文章
- POJ 2140 Herd Sums
		
http://poj.org/problem?id=2140 Description The cows in farmer John's herd are numbered and branded w ...
 - 转载:hdu 题目分类 (侵删)
		
转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012. ...
 - POJ解题经验交流
		
感谢范意凯.陈申奥.庞可.杭业晟.王飞飏.周俊豪.沈逸轩等同学的收集整理. 题号:1003 Hangover求1/2+1/3+...1/n的和,问需多少项的和能超过给定的值 类似于Zerojudg ...
 - 杭电ACM分类
		
杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...
 - 算法之路 level 01 problem set
		
2992.357000 1000 A+B Problem1214.840000 1002 487-32791070.603000 1004 Financial Management880.192000 ...
 - 【转】POJ百道水题列表
		
以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...
 - hdu 4193 Non-negative Partial Sums 单调队列。
		
Non-negative Partial Sums Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/32768 K (Jav ...
 - hdu 4193 Non-negative Partial Sums
		
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4193 题意:给出一个n数列,要求把前i(1<=i<=n)个数移到剩余数列的后面形成新的数列 ...
 - HDU 4193 	Non-negative Partial Sums(想法题,单调队列)
		
HDU 4193 题意:给n个数字组成的序列(n <= 10^6).求该序列的循环同构序列中,有多少个序列的随意前i项和均大于或等于0. 思路: 这题看到数据规模认为仅仅能用最多O(nlogn) ...
 
随机推荐
- hdu 1847 Good Luck in CET-4 Everybody! 博弈论
			
方法一:找规律,很容易知道 #include<stdio.h> int main(){ int n; while(scanf("%d",&n)!=EOF){ p ...
 - SQL 两张结构一样的表合并查询 .
			
select * from table1 union all select * from table2 union all 是所有的都显示出来: select * from table1 union ...
 - Android开发之技术文章索引
			
Activity: 1.PreferenceActivity Fragment: 1.fragment中套用PagerSlidingTabStrip,切换底部时viewpager消失的解决 Widge ...
 - Android开发框架之xUtils学习
			
1.一个非作者弄的xUtils API文档: http://xutilsapi.oschina.mopaas.com/overview-summary.html 2.使用xUtils用户的一些博客文档 ...
 - Java面试题-并发容器和框架
			
1. 如何让一段程序并发的执行,并最终汇总结果? 答:使用CyclicBarrier 和CountDownLatch都可以,使用CyclicBarrier 在多个关口处将多个线程执行结果汇总,Coun ...
 - nginx+lua+redis实现logserver
			
http://www.baidu.com/s?wd=nginx lua&pn=10&oq=nginx lua&tn=baiduhome_pg&ie=utf-8& ...
 - 1837. Isenbaev's Number(floyd)
			
1837 被数据结构部分打击的不行了 换地 刷点简单的 图论第一题 floyd水过 #include <iostream> #include<cstdio> #include& ...
 - jquery-autocomplete 参数说明
			
minChars (Number): 在触发autoComplete前用户至少需要输入的字符数.Default: 1,如果设为0,在输入框内双击或者删除输入框内内容时显示列表 * width (Num ...
 - golang资料整理   (整理 中...)
			
网站guide 官方文档 国内镜像 安装go 之后,用godoc 来安装自己本地的文档服务器, godoc -http=:8080 打开浏览器 输入localhost:8080 就可以看到文档说明了. ...
 - [转] windows7 IIS管理器 在计算机“.”上没有找到WAS服务
			
原文地址:windows7 IIS管理器 在计算机"."上没有找到WAS服务作者:云中的风 OS:windows7旗舰版 产生问题原因:运行金蝶K3-HR时客户端提示中间层服务器不 ...