时间限制: 1 Sec 内存限制: 128 MB
题目描述
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).
输入
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).
输出
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.
样例输入
5
1 3
2 11
3 12
4 100
5 9999
样例输出
1 1
2 5
3 4
4 392
5 4165834
打表打出来的,有通项公式
a(n) = floor((n^2+3*n+20)/24+(2*n+3)*(-1)^n/16)
#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 10100;
typedef pair<int,int>P;
int dp[N];
int main()
{
int cnt=0;
dp[3]=1;
for(int i=3;i<N-50;i+=6,cnt++)
{
dp[i+2]=dp[i]+cnt;
dp[i+4]=dp[i+2]+cnt+1;
dp[i+6]=dp[i+4]+cnt+2;
}
int T;
scanf("%d",&T);
while(T--)
{
int id,n;
scanf("%d%d",&id,&n);
if(n%2==0) n-=3;
printf("%d %d\n",id,dp[n]);
}
return 0;
}