Pen Counts(UVALIVE 6174)

Sample Input

5

1  3

2 11

3 12

4 100

5 9999

Sample Output

1 1

2 5

3 4

392

5 4165834 

 

题意:

用长度为 n 的绳子围三角形

同一三角形的旋转是相同的,反射是不同的

意思就是,对于等腰和等边三角形来说,不论怎么旋转只能算一种,其余的算两种

思路:

设定 a<=b<=c,枚举a的范围,求出b的范围,然后判断c与a和b的关系

(1)、确定a的范围:1 <= a <= n/3

(2)、确定b的范围:(n- 2*a)/ 2 + 1  < =  b  <=  (n-a) / 2

①:a+b+c=n

②:a+b>c(两边之和大于第三边)

知: b>(n- 2*a)/ 2 即 b>=(n- 2*a)/ 2 + 1

①:a+b+c=n

②:b<= c

知:b<= (n-a) / 2

(3)、通过b的范围确定c的大小

 

CODE:

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
typedef long long LL;
using namespace std;
#define memset(a,n) memset(a,n,sizeof(a))
#define INF 0x3f3f3f3f
const int MAX = 403;


int main()
{
    int t,k,n;
    cin>>t;

    while(t--)
    {
        cin>>k>>n;

        int ans=0;
        int minn=0,maxx=0;

        for(int i=1;i<=n/3;i++)
        {
            minn=(n-2*i)/2+1;
            minn=max(i,minn);
            maxx=(n-i)/2;

            ans+=abs(maxx-minn+1)*2; // 先按照两种来计算

            for(int j=minn;j<=maxx;j++){
                int c=n-i-j;
                if(c==i&&c==j){ // 等边三角形减去一种
                    ans--;
                    continue;
                }

                if(c==i||c==j||i==j) // 等腰三角形减去一种
                    ans--;
            }
        }

        cout<<k<<' '<<ans<<endl;
    }
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值