算是水题吧
给定三角形的周长,求能够组成三角形的个数(此说法有bug,继续分析题意)
根据题意可知:当三角形三边各不相同时 看做 两个三角形(需特殊处理)
//#include<bits/stdc++.h> // 这是个 万能头文件,不过刚刚 vj 上 没编过
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
int T, k, n, x, hy, ly, ans;
scanf("%d", &T);
while(T--)
{
scanf("%d%d", &k, &n);
ans = 0;
for(x = 1; x <= n/3; ++x)
{
ly = max(x, n/2-x+1);
hy = (n-x)/2;
if(x == ly) ans--;
if(x != hy && 2*hy == n-x) ans--;
ans += (hy-ly+1) * 2;
}
printf("%d %d\n", k, ans);
}
return 0;
}