Problem Description
Jason buys an N-metre-long bamboo fence, which he intends to use as a triangular chicken farm for all the N-metre-long bamboo fences. For convenience, the three-side length of the chicken farm is a positive integer. At the same time, he wanted to make his chicken farm look more beautiful, requiring the length of the three sides to be within a range.
Now, he wants to know how many different schemes have made the surrounding chicken farm meet the requirements?
Input
The input contains multiple sets of data. Input data The first line is a positive integer n, which indicates the length of the bamboo fence.
In the next three rows, the two positive integers of line I are xi,yi. The range of side length AI that represents the I-edge of the triangle is within [xi,yi].
Note: Jason rules a1≤a2≤a3.
Output
Outputs an integer that represents the number of different scenarios that satisfy the requirement.
Conventions:
For the second row to the fourth row, there are 1≤xi≤yi≤n
For 50% of data n≤5000
For 100% of data n≤200000
Sample Input123 5 Sample Output2
#include <stdio.h> #include <algorithm>using namespace Std;int s,l1,r1,l2,r2,l3,r3;int main () {while ( ~SCANF ("%d", &s)) { int i,j,k,ans = 0; int Max1,max2,min1,min2,tem; scanf ("%d%d%d%d%d%d", &L1,&R1,&L2,&R2,&L3,&R3); for (i = L1; i<=r1; i++) { tem = (s-i)/2; if (i>tem) break ; Min1 = max (l2,i);//Determine the left edge of the second largest side min1 = max (min1,s/2-i+1);//Ensure that the sum of the two sides is greater than the third side, can form a triangle max1 = min (r2,tem); min2 = Max (l3,tem+ (((s-i)%2)? 1:0)); max2 = min (r3,s-i-min1); tem = MIN (max1-min1+1,max2-min2+1); if (tem>0) ans+=tem; } printf ("%d\n", ans); } return 0;}
FZU2127: Chicken Farm