Description
Pasha has a wooden stick of some positive integer length n. He wants to perform exactly three cuts to get four parts of the stick. Each part must have some positive integer length and the sum of these lengths will obviously be n.
Pasha likes rectangles but hates squares, so he wonders, how many ways are there to split a stick into four parts so that it's possible to form a rectangle using these parts, but is impossible to form a square.
Your task is to help Pasha and count the number of such ways. Two ways to cut the stick are considered distinct if there exists some integer x, such that the number of parts of length x in the first way differ from the number of parts of length x in the second way.
Input
The first line of the input contains a positive integer n (1 ≤ n ≤ 2·109) — the length of Pasha's stick.
Output
The output should contain a single integer — the number of ways to split Pasha's stick into four parts of positive integer length so that it's possible to make a rectangle by connecting the ends of these parts, but is impossible to form a square.
Sample Input
6
1
20
4
Hint
There is only one way to divide the stick in the first sample {1, 1, 2, 2}.
Four ways to divide the stick in the second sample are {1, 1, 9, 9}, {2, 2, 8, 8}, {3, 3, 7, 7} and {4, 4, 6, 6}. Note that {5, 5, 5, 5} doesn't work.
通过两组样例找规律可解,暴力也可以解,这里暴力time: 931MS,也算是险过吧。。。
#include<stdio.h>
#include<iostream>
#include<string.h>
using namespace std;
#define ll long long int
int main()
{
ll n;
while(~scanf("%lld",&n))
{
ll output=0;
//printf("%lld\n",n/4);
for(ll i=1;i<=n/4;i++)
{
// printf("%lld\n",n-i*2);
if((n-i*2)%2==0)
output++;
}
if(n%4==0)output-=1;
printf("%lld\n",output);
}
}
#include<stdio.h>
int main()
{
long long n;
scanf("%lld",&n);
if(n%2!=0)//注意如果是奇数是不可能组成长方形的,只有0种方案,这个要单独拿出来考虑。
printf("0\n");
else
{
if(n/2%2==1)
printf("%lld\n",n/4);
else
printf("%lld\n",n/4-1);
}
return 0;
}
本文详细介绍了如何通过分析两组样例数据找出规律,进而解决涉及切割木棍并形成特定形状的数学问题。通过提供输入样例和预期输出,文章指导读者采用逻辑思考和算法实现来求解此类问题。
704

被折叠的 条评论
为什么被折叠?



