Rikka with wood sticks
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 600 Accepted Submission(s): 169
Yuta have a wood stick of length n which consists of n linked sticks of length 1. So it has n−1 connection points. Yuta finds that some sticks of length 1 of the wood stick are not strong. So he wants to choose three different connection points to cut it into four wood sticks and only one of them contains wood sticks which are not strong. And Yuta wants to minimize the length of this piece which contains bad wood sticks. Besides, Rikka wants to use the other three wood sticks to make a triangle. Now she wants to count the number of the ways to cut the wood sticks which can make both Yuta and herself happy.
It is too difficult for Rikka. Can you help her?
3
5 1
3
0
#include<stdio.h>
#include<algorithm>
typedef __int64 ll ;
int n , m ;
int l , r ; bool ok (int a , int b , int c)
{
if (a + b > c && a + c > b && b + c > a)
return true ;
return false ;
} ll calc2 (int lg , int wd)
{
if (lg == wd) return ;
if (lg < wd) std::swap (lg , wd) ;
int x = (lg - wd)/ ;
if (x == ) x ++ ;
if (ok (x , lg - x , wd))
return lg - - (x - ) * ;
else
return lg - - x * ;
} ll calc1 (int lg)
{
ll tot = ;
for (int i = ; i <= lg/ ; i++) {
tot += calc2 (i , lg - i) ;
}
return tot ;
} int main ()
{
//freopen ("a.txt" , "r" , stdin ) ;
while (~ scanf ("%d%d" , &n, &m)) {
l = n , r = ;
for (int i = ; i < m ; i++) {
int x ;
scanf ("%d" , &x) ;
l = std::min (l , x) ;
r = std::max (r , x) ;
}
if (l == ) {
printf ("%I64d\n" , calc1 (n - r)) ;
}
else if (r == n) {
printf ("%I64d\n" , calc1 (l - )) ;
}
else printf ("%I64d\n" , calc2 (l - , n - r)) ;
}
return ;
}