hdu4486 Pen Counts(水题)
Pen Counts
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 224 Accepted Submission(s): 127
Xiaoyan is getting three new chickens, Lucy, Charlie and CC. She wants to build a chicken pen so that each chicken has its own, unobstructed view of the countryside. The pen will have three straight sides; this will give each chicken its own side so it can pace back and forth without interfering with the other chickens. Xiaoyan finds a roll of chicken wire (fencing) in the barn that is exactly N feet long. She wants to figure out how many different ways she can make a three sided chicken pen such that each side is an integral number of feet, and she uses the entire roll of fence.
Different rotations of the same pen are the same, however, reflections of a pen may be different (see below).


Each data set consists of a single line of input. It contains the data set number, K, and the length of the roll of fence, N, (3 <= N <= 10000).
1 3
2 11
3 12
4 100
5 9999
2 5
3 4
4 392
5 4165834
这个题我写了大部分,线性时间内求得三角形的数目没问题,却在判断三角形中等腰三角形的数目时出了问题,无奈之下百度一下解题报告,看完后恍然大悟,对于每一个确定的a,它的等腰三角形数目最多为两个,对于等边三角形则要注意不要多减1次
#include<stdio.h>
int main()
{
int t,n,i,m,ans,temp1,temp2,a,b,c,temp;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
temp1=m/3;
ans=0;
for(a=1;a<=temp1;a++)
{
temp2=(m-a)/2;//b上限
temp=0;
b=(m/2-a+1)>a?(m/2-a+1):a;//b下限
if(a==b)
{
ans--;
temp=a;
}
if(temp!=temp2&&temp2==m-a-temp2)//判断b==c,并防止一个等腰三角形三角形减去两次
ans--;
ans+=2*(temp2-b+1);//不管等腰三角形先都加2,在上面判断减一
}
printf("%d %d\n",n,ans);
}
return 0;
}
hdu4486 Pen Counts(水题)的更多相关文章
- hdu 4648 - Magic Pen 6(“水”题)
摘自题解: 题意转化一下就是: 给出一列数a[1]...a[n],求长度最长的一段连续的数,使得这些数的和能被M整除. 分析: 设这列数前i项和为s[i], 则一段连续的数的和 a[i]+a[i+1] ...
- HDU 5578 Friendship of Frog 水题
Friendship of Frog Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.ph ...
- poj1564 Sum It Up dfs水题
题目描述: Description Given a specified total t and a list of n integers, find all distinct sums using n ...
- hdu 4486 Pen Counts
Pen Counts Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- HDOJ 2317. Nasty Hacks 模拟水题
Nasty Hacks Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tota ...
- ACM :漫漫上学路 -DP -水题
CSU 1772 漫漫上学路 Time Limit: 1000MS Memory Limit: 131072KB 64bit IO Format: %lld & %llu Submit ...
- ytu 1050:写一个函数,使给定的一个二维数组(3×3)转置,即行列互换(水题)
1050: 写一个函数,使给定的一个二维数组(3×3)转置,即行列互换 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 154 Solved: 112[ ...
- [poj2247] Humble Numbers (DP水题)
DP 水题 Description A number whose only prime factors are 2,3,5 or 7 is called a humble number. The se ...
- gdutcode 1195: 相信我这是水题 GDUT中有个风云人物pigofzhou,是冰点奇迹队的主代码手,
1195: 相信我这是水题 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 821 Solved: 219 Description GDUT中有个风云人 ...
随机推荐
- SpringMVC可以配置多个拦截后缀*.html和.do等
一个servlet可以配置多个servlet-mapping, 因此在xml文件中我们可以这样配置: <!-- springmvc配置 --> <servlet> <se ...
- LCA问题的ST,tarjan离线算法解法
一 ST算法与LCA 介绍 第一次算法笔记这样的东西,以前学算法只是笔上画画写写,理解了下,刷几道题,其实都没深入理解,以后遇到新的算法要把自己的理解想法写下来,方便日后回顾嘛>=< R ...
- 131. Palindrome Partitioning
题目: Given a string s, partition s such that every substring of the partition is a palindrome. Return ...
- Vue.js 基础示例
为 Vue.js 初学者写了一些简单的示例,在线示例 示例源码 了解更多请查看 Vue.js 官网文档:http://vuejs.org.cn/guide/
- 关于mIdleHandlers 空闲消息
模拟情况说明 创建一个handler对象 该handler持有的是主线程 1.先发送一个延时20秒的message what=35;2.紧接着又发送一个延时10秒的Runnable3.在该Runnab ...
- SSH框架应用中常用Jar包用途介绍
struts2需要的几个jar包:1)xwork-core-2.1.62)struts2-core-2.1.83)ognl-2.7.34)freemarker-2.3.155)commons-io-1 ...
- BZOJ_1611_[Usaco2008_Feb]_Meteor_Shower流星雨_(bfs)
描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1611 网格图起始位置(0,0),不同时间会有流星落下,导致之后的时间里,该点以及周围四个点都不 ...
- sql - and - or
sql - and SQL AND links together two or more conditional statements for increased filtering when run ...
- oracle的exp、imp命令
1.EXP a>完全模式 full=y EXP USER/PASSWORD@DB (AS ROLE) BUFFER=64000 FILE=C:\FULL.DMP FULL=Y b>用户模式 ...
- 嵌入式开发软件环境:uboot、kernel、rootfs、data布局分析
uboot+linux的整体方案 开发板的datasheet中都有详细的地址空间的划分,其中比较重要的两块是:DDR地址空间和Flash地址空间.DDR空间是系统和应用的运行空间,一般由linux系统 ...