WoolTime
limit:8000/4000 MS (java/others) Memory limit:262144/262144 K (java/others)
Total submission (s): 686 Accepted Submission (s): 192
problem DescriptionAt dawn, Venus sets a second task for psyche.
She is to cross a river and fetch golden wool from violent sheep who graze on the other side.
The sheep is wild and tameless, so psyche keeps on throwing sticks to keep them away.
There is n Sticks on the ground, the length of the i -th Stick is a i .
If the new stick she throws forms a triangle with any of the sticks on the ground, the sheep would be irritated and attack her .
Psyche wants to throw a new stick whose length is within the interval [ L r . Help her calculate the number of valid sticks she can throw next time.
InputThe first line of input contains an integer T ( 1 " Span id= "mathjax-span-26" class= "Mo" style= "font-family:mathjax_main-web; Padding-left:0.27em ">≤ t ≤ 10 ) , which denotes the number of test cases.
For each test case, the first line of input contains a single integer < Span style= "Position:absolute; Left:0em; Top:-4em ">n L r (2≤N≤ ten 5 ,1≤L≤R≤ ten ) .
The second line contains n Integers, the i -th integer denotes a i (1≤ a i ≤ ten ) .Outputfor each test case, print the number of ways to throw a stick.
Sample Input
22 1 31 14 3 101 1 2 4
Sample Output
- Hint in the first example, $2, 3 $ is available. In the second example, $6, 7, 8, 9, ten $ are available.
SourceBestcoder 2nd Anniversaryrecommendwange2014 | We have carefully selected several similar problems for you:5722 5721 5717 5716 5715 Test Instructions: I did this problem when WA a lot of hair, found to think too much. give you n number and l,r. Ask you how many numbers you have in the "L,r" range.can'tand any of the two numbers in the a array make up a triangle.
Puzzle : First give the n number a sort, you will find that in this n number, the most not to take and the largest number is A[n] (n starting from 1). For I:1~n-1, the most unable to take the interval is "a[i+1]-a[i]+1,a[i+1]+a[i]-1", enumerate the i:1~n-1 of this interval, and then compared to the "L,r", take its relative to "l,r" complement set.
AC Code:
#include <stdio.h> #include <iostream> #include <algorithm>typedef long long ll;typedef unsigned long Long Ull;const int n=100010; LL A[n]; int main () {int n,t; LL R, L; ll ans;scanf ("%d", &t), while (t--) {ans=0;scanf ("%d%i64d%i64d", &n,&l,&r); for (LL i=1;i<=n;i++) scanf ("%i64d", &a[i]); Std::sort (a,a+n+1);/*ll res=a[n]+a[n-1]; ll Sd=std::max (l,res); Ans=r-sd+1;*/ll l,r;for (LL i=n-1;i>=1;--i) { l=a[i+1]-a[i]+1; R=a[i+1]+a[i]-1;if (l>r| | R<l) continue;if (r>r) ans+=r-r; R=l-1;if (l>r) break; }if (l<=r) ans+=r-l+1;printf ("%i64d\n", ans); }}
HDU 5720 Wool bestcoder 2nd Anniversary (interval coverage)