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;
}
}