hdu 4486 Pen Counts

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

 

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=0;i<p;i++){
        ans=0;
        scanf("%d %d",&num,&n);
        for(int a=1;a<=n/3;a++){
            int b1=(n-2*a)/2+1;
            int b2=(n-a)/2;
            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+1)*2;
        }
        printf("%d %d\n",num,ans);
    }
    return 0;
}

 

全部评论

相关推荐

点赞 评论 收藏
分享
11-15 18:39
已编辑
西安交通大学 Java
全村最靓的仔仔:卧槽,佬啥bg呢,本也是西交么
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务