Hdoj 5720 Wool

Source: Internet
Author: User

Wool Time limit:8000/4000 MS (java/others) Memory limit:262144/262144 K (java/others)
Total submission (s): 647 Accepted Submission (s): 185


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 [< /span>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 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
HintIn the first example, $2, 3 $ is available. In the second example, $6, 7, 8, 9, ten $ are available.

Sourcebestcoder 2nd Anniversary


Test instructions is roughly: give the number and length of the existing sticks and then give the length range of the available sticks. But to make any three sticks can not form a triangle, the length of the stick is a total number of options.

Uphold the sum of the two sides less than equal to the third side cannot form a triangle

/*

Test data:
1000
4 1 20
5 6 7 8

4 1 150
2 3 7 100

2 1 1000000000000000000
2 3

4 1 1000000000000000000
2 3 7 100

4 1000000 1000000000000000
2 3 7 100

4 2 3
1 1 1 1

4 1 100
2 3 9 100

2 2 2
1 5

2 2 2
1 1


2 2 2
2 3
*/




#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #define MAXN    100010using namespace Std;long long A[maxn];int main () {int t,n;    Long Long L,r,xl,xr,ans;    scanf ("%d", &t);        while (t--) {scanf ("%d%i64d%i64d", &n,&l,&r);        for (int i=1;i<=n;++i) scanf ("%i64d", &a[i]);        ans=0;        Sort (a+1,a+n+1);        xl=l>1?l:1; Xr= (a[2]-a[1]) <=r?        (A[2]-a[1]): R;        if (XL&LT;=XR) ans+=xr-xl+1; for (int i=3;i<=n;++i) {if (a[i]-a[i-1) >=l&& (a[i-1]+1) <=r&& (a[i]-a[i-1]) >=a                [I-1]+a[i-2]) {xl=l>a[i-1]+a[i-2]?l: (a[i-1]+a[i-2]);                Xr=r<a[i]-a[i-1]?r: (A[i]-a[i-1]);            if (XL&LT;=XR) ans+=xr-xl+1;            }} if (A[n]+a[n-1]<=r) {if (a[n]+a[n-1]>=l) ans+=r-(a[n]+a[n-1]) +1;            Else    ans+=r-l+1;    } printf ("%i64d\n", ans); } return 0;}


Hdoj 5720 Wool

Related Keywords:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.