6174 Pen Counts(规律题)

欢迎访问https://blog.csdn.net/lxt_Lucia~~

宇宙第一小仙女\(^o^)/~~萌量爆表求带飞=≡Σ((( つ^o^)つ~ dalao们点个关注呗~~

 

----------------------------------------我只是一条可爱哒分界线-------------------------------------------

 

一、问题:

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 offence. 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 ≤ l0000).

 

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

 

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

 

二、题意:

用总长为 n 的栅栏围成一个三角形的鸡圈(必须全部用完),即三角形周长为 n 。

本题中:旋转所得与本身按同一种,但也有种特殊情况:

一般三角形(非等腰/等边),上下翻转后得到的三角形与其本身按两种计算(等腰/等边三角形翻转后仍按同一种)。

给出 n,求最多可以组成多少种三角形。

 

三、思路:

当时没想出来,后来想用“李杰暴力法”打表来着,不过来不及了哈哈。

(注意直接暴力提交会T,可以暴力打出来表再交)emmm... ..

好叭..... 正常思路是:枚举第一条边,找第二条边上下界,先都按普通三角形处理(都乘2),出现等腰/等边再减去。

求第二边上下界:

设三边为x , y , z(x <= y <= z),枚举 x (即 x 和 n 已知)。 

因为两边之差小于第三边,所以 0 <= z - y < x 。

又 x + y + z = n ,得(n - 2x) / 2 < y <= (n - x) / 2.

n / 2 - x + 1 <= y <= (n - x) / 2

 

四、代码:

#include <cstdio>
#include <iostream>
#define read(x) scanf("%d",&x)
#define fori(a,b) for(int i=a;i<=b;i++)

using namespace std;

int main()
{
    int T, k, n, ymin, ymax;
    read(T);
    while(T--)
    {
        int ans = 0;
        read(k),read(n);
        fori(1, n/3)
        {
            ymin = max(n/2-i+1,i);
            ymax = (n-i)/2;
            ans += (ymax-ymin+1)*2;
            if(i == ymin)
                ans--;
            if(i != ymax && ymax == n-i-ymax)
                ans--;
        }
        printf("%d %d\n", k,ans);
    }
    return 0;
}

 

------------------------------------------我也是有底线的----------------------------------------------------

欢迎访问https://blog.csdn.net/lxt_Lucia~~

宇宙第一小仙女\(^o^)/~~萌量爆表求带飞=≡Σ((( つ^o^)つ~ dalao们点个关注呗~~

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值