Pen Counts

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 224    Accepted Submission(s): 127

Problem Description
Chicken farmer 
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).


 
Input
The first line of input contains a single integer P,(1<= P <=1000), which is the number of data sets that follow. Each data set should be processed identically and independently.

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).

 
Output
For each data set there is a single line of output. It contains the data set number, K, followed by a single space which is then followed by an integer which is the total number of different three-sided chicken pen configurations that can be made using the entire roll of fence.

 
Sample Input
5
1 3
2 11
3 12
4 100
5 9999
 
Sample Output
1 1
2 5
3 4
4 392
5 4165834
 
Source
 

这个题我写了大部分,线性时间内求得三角形的数目没问题,却在判断三角形中等腰三角形的数目时出了问题,无奈之下百度一下解题报告,看完后恍然大悟,对于每一个确定的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(水题)的更多相关文章

  1. hdu 4648 - Magic Pen 6(“水”题)

    摘自题解: 题意转化一下就是: 给出一列数a[1]...a[n],求长度最长的一段连续的数,使得这些数的和能被M整除. 分析: 设这列数前i项和为s[i], 则一段连续的数的和 a[i]+a[i+1] ...

  2. HDU 5578 Friendship of Frog 水题

    Friendship of Frog Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.ph ...

  3. poj1564 Sum It Up dfs水题

    题目描述: Description Given a specified total t and a list of n integers, find all distinct sums using n ...

  4. hdu 4486 Pen Counts

    Pen Counts Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  5. HDOJ 2317. Nasty Hacks 模拟水题

    Nasty Hacks Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tota ...

  6. ACM :漫漫上学路 -DP -水题

    CSU 1772 漫漫上学路 Time Limit: 1000MS   Memory Limit: 131072KB   64bit IO Format: %lld & %llu Submit ...

  7. ytu 1050:写一个函数,使给定的一个二维数组(3×3)转置,即行列互换(水题)

    1050: 写一个函数,使给定的一个二维数组(3×3)转置,即行列互换 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 154  Solved: 112[ ...

  8. [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 ...

  9. gdutcode 1195: 相信我这是水题 GDUT中有个风云人物pigofzhou,是冰点奇迹队的主代码手,

    1195: 相信我这是水题 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 821  Solved: 219 Description GDUT中有个风云人 ...

随机推荐

  1. .NET(C#):灵活运用CryptoStream,加密不是必须用CryptoStreamMode.Write

    首先.NET中的ICryptoTransform是单向的,也就是只能从一个状态将数据转化成另一个状态,反之是不可以的.当然手动 操作ICryptoTransform还是比较繁琐的,通过CryptoSt ...

  2. android一个纠结的VFY错误

    08-16 09:06:45.018: W/dalvikvm(2286): VFY: unable to resolve static method 3273: Lorg/slf4j/LoggerFa ...

  3. android gridview按钮边框和定制点击颜色

    <?xml version="1.0" encoding="utf-8"?> <GridView xmlns:android="ht ...

  4. 查看jdk的位数

    public class Test { public static void main(String[] args) { System.out.println("bit of JVM is ...

  5. 网络基本功(八):细说TCP滑动窗口

    https://community.emc.com/message/842129#842129

  6. SPRING IN ACTION 第4版笔记-第七章Advanced Spring MVC-002- 在xml中引用Java配置文件,声明DispatcherServlet、ContextLoaderListener

    一.所有声明都用xml 1. <?xml version="1.0" encoding="UTF-8"?> <web-app version= ...

  7. android 颜色收集及部分gridview样式设置

    < ?xml version="1.0" encoding="utf-8" ?> < resources> < color nam ...

  8. Oracle系列之序列

    涉及到表的处理请参看原表结构与数据  Oracle建表插数据等等 语法结构:创建序列 create sequence sequence_name start with num increment by ...

  9. BZOJ1334: [Baltic2008]Elect

    1334: [Baltic2008]Elect Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 386  Solved: 201[Submit][Sta ...

  10. Java C# MD5 加密串一致性

    Java C# MD5 加密串一致性   Java public final static String md5(String s) { char hexDigits[] = { '0', '1',  ...