Pen Counts

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

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
 
Recommend
liuyiding
养个鸡真难啊。。。
没怎么做过数论的题,感觉这种题更加锻炼思维。。。
已知a<b<c 
可以先枚举最短边a,他的范围肯定在[1,n/3].
然后还有b,c两个位置数啊,怎么办呢。。。。但是我们知道三角形的其他性质啊,两边之差小于第三边。
所以找b,c之间的关系,令b-c=t;---------①
所以 0<=  t  <a------③
有知道b+c=n------------②
联合①②就能推出b的式子来b=(n-a-t)/2,又已知t的范围,即③,所以能得到b的范围  (n-2a)/2+1,(n-a)/2] ,就能知道可以构造多少个三角形。 (b取最小值时取到的要+1)
然后再判断有没有等边三角形或者等腰三角形的情况。
因为b是第二短的边,所以b取最小值(不能比a小)时可能会出现与最短边a相等的情况,判断一下。。。
当取到最大值时可能会出现与c相等的情况。判断一下。。。(要注意判断是不是等边三角形,是等边三角形可能在取最小值时就已经记录过了。所以要不是等边三角形&& b取最大值!=c  )
 
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std; int main()
{
int p;
int n;
int num;
int ans;
scanf("%d",&p);
for(int i=;i<p;i++){
ans=;
scanf("%d %d",&num,&n);
for(int a=;a<=n/;a++){
int b1=(n-*a)/+;
int b2=(n-a)/;
int b=max(b1,a);
int c=n-a-b;
if(b==a){
ans--;
}
if(a!=b2&&b2==n-a-b2){
ans--;
}
ans+=(b2-b+)*;
}
printf("%d %d\n",num,ans);
}
return ;
}

hdu 4486 Pen Counts的更多相关文章

  1. hdu4486 Pen Counts(水题)

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

  2. hdu 5277 YJC counts stars

    hdu 5277 YJC counts stars 题意: 给出一个平面图,n个点,m条边,直线边与直线边之间不相交,求最大团的数目. 限制: 1 <= n <= 1000 思路: 因为平 ...

  3. hdu 5277 YJC counts stars 暴力

    YJC counts stars Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...

  4. Regionals 2012, North America - Greater NY 解题报告

    这套题..除了几何的都出了 完全没时间学几何.杯具 A,B,J 水题不解释 C.Pen Counts 这题的话 写几个不等式限制边得范围就行了 然后枚举最小边 D.Maximum Random Wal ...

  5. HDU 4648 Magic Pen 6 (。。。。。。。。。。)

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

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

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

  7. HDU 4648 Magic Pen 6

    题目链接 6Y什么水平.. #include <cstdio> #include <cstring> #include <string> #include < ...

  8. HDU 4648 Magic Pen 6 思路

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

  9. HDU 5938 Four Operations(四则运算)

    p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...

随机推荐

  1. 附近有什么?8款可以查周边的App

    如今科技发达的时代,手机的功能不仅仅只是能通讯聊天,而是逐渐的走进了人们的生活中.因为有了APP,我们的生活才更丰富,并且有很多是我们生活中不可缺少的软件,而这些软件便是根据手机中的GPS定位系统而来 ...

  2. Redis的快照持久化-RDB与AOF

    Redis持久化功能 Redis为了内部数据的安全考虑,会把本身的数据以文件形式保存到硬盘中一份,在服务器重启之后会自动把硬盘的数据恢复到内存(redis)的里边. 数据保存到硬盘的过程就称为“持久化 ...

  3. Apache Kafka 快速入门

    概述 Apache Kafka是一个分布式发布-订阅消息系统和强大的队列,可以处理大量的数据,将消息从一个端点传递到另一个端点.Kafka适合离线和在线消息消费,Kafka消息保存在磁盘上,并在集群内 ...

  4. 分布式环境中,模块数据交互协议分析 (百度brpc)

    1. 背景 之前听到同事说,要为自己的模块考虑写个数据协议.今天有空想了一下.写出来,方便后续使用. 开源代码brpc中可以支持多种协议,nshead.redis.mongo等20多种协议. 2. 什 ...

  5. R语言之Random Forest随机森林

    什么是随机森林? 随机森林就是通过集成学习的思想将多棵树集成的一种算法,它的基本单元是决策树,而它的本质属于机器学习的一大分支——集成学习(Ensemble Learning)方法.随机森林的名称中有 ...

  6. C#反射实现 C# 反射 判断类的延伸类型 使用代码生成工具Database2Sharp快速生成工作流模块控制器和视图代码 C# ADO.NET的SqlDataReader对象,判断是否包含指定字段 页面中添加锚点的几种方式 .net 简单实用Log4net(多个日志配置文件) C# 常用小点

    C#反射实现   一.反射概念: 1.概念: 反射,通俗的讲就是我们在只知道一个对象的内部而不了解内部结构的情况下,通过反射这个技术可以使我们明确这个对象的内部实现. 在.NET中,反射是重要的机制, ...

  7. Python 获得最近一个月的每天的日期

    直接上代码: #coding:utf-8 # from common.contest import * import datetime import time begin_date = (dateti ...

  8. 整体C#与Sql培训内容及结构

    图如果看不清可以右键存图片到本地

  9. 看雪CTF第十题

    __int64 sub_140006F50() { __int64 v0; // r8@1 __int64 v1; // r9@1 signed __int64 len; // rax@1 __int ...

  10. [转]剑指offer之Java源代码

    一.引言 <剑指offer>可谓是程序猿面试的神书了,在面试中帮了我很多,大部分面试的算法题都会遇到原题或者是类似的题.但是书上的代码都是C版的,我在这里整理了一份Java版的代码供大家学 ...