HDU 5720 Wool
来源:互联网 发布:域名后缀cc 编辑:程序博客网 时间:2024/04/30 18:51
Problem Description
At 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 are wild and tameless, so Psyche keeps on throwing sticks to keep them away.
There aren sticks on the ground, the length of the i -th stick is ai .
If the new stick she throws forms a triangle with any two sticks on the ground, the sheep will 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.
She is to cross a river and fetch golden wool from violent sheep who graze on the other side.
The sheep are wild and tameless, so Psyche keeps on throwing sticks to keep them away.
There are
If the new stick she throws forms a triangle with any two sticks on the ground, the sheep will be irritated and attack her.
Psyche wants to throw a new stick whose length is within the interval
Input
The first line of input contains an integer T (1≤T≤10) , which denotes the number of test cases.
For each test case, the first line of input contains single integern,L,R (2≤n≤105,1≤L≤R≤1018) .
The second line containsn integers, the i -th integer denotes ai (1≤ai≤1018) .
For each test case, the first line of input contains single integer
The second line contains
Output
For 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
25HintIn the first example, $ 2, 3 $ are available.In the second example, $ 6, 7, 8, 9, 10 $ are available.先排个序,找出相邻的两个长度的不可行区间,然后合并即可
#include<set>#include<map>#include<cmath>#include<stack>#include<queue>#include<bitset>#include<cstdio>#include<string>#include<cstring>#include<iostream>#include<algorithm>#include<functional>#define rep(i,j,k) for (int i = j; i <= k; i++)#define per(i,j,k) for (int i = j; i >= k; i--)using namespace std;typedef long long LL;const int low(int x) { return x&-x; }const int N = 1e5 + 10;const int mod = 998244353;const int INF = 0x7FFFFFFF;int T, n, t;LL a[N], L, R, l[N], r[N], b[N], ans;bool check(LL &l, LL &r){l = max(l, L); r = min(r, R);return l <= r;}bool cmp(const int &x, const int &y){return l[x] < l[y];}int main(){scanf("%d", &T);while (T--){scanf("%d%lld%lld", &n, &L, &R);rep(i, 1, n) scanf("%lld", &a[i]);sort(a + 1, a + n + 1);ans = t = 0;rep(i, 1, n - 1){l[i] = a[i + 1] - a[i] + 1;r[i] = a[i] + a[i + 1] - 1;if (check(l[i], r[i])) b[t++] = i;}sort(b, b + t, cmp);for (LL i = 0, j, k; i < t; i = j){for (j = i, k = r[b[i]]; j < t&&l[b[j]] <= k; j++) k = max(k, r[b[j]]);ans += k - l[b[i]] + 1;}printf("%lld\n", R - L + 1 - ans);}}
0 0
- Hdu 5720 Wool
- hdu 5720 Wool
- HDU 5720 Wool
- HDU-5720 Wool
- hdu 5720 wool
- HDU 5720 Wool
- HDU 5720 Wool (贪心)
- HDU 5720 Wool(排序 遍历)
- 【HDU 5720】Wool(排序+排序/扫描线。。。)
- hdu 5720 Wool(贪心,扫描线,区间合并)
- HDU 5720 Wool BestCoder 2nd Anniversary (区间覆盖)
- hdu 5720 - Wool (线段交的长度)
- HDOJ 5720 Wool
- codeforces 148 Not Wool Sequences
- codeforces 148 Not Wool Sequences
- China-Australia FTA Boosts Wool Industry
- CF 238A Not Wool Sequences
- 【HDOJ】【BestCoder 2nd Anniversary】1003 Wool
- HTML5 Video Events and API
- HDU 5100 Chessboard
- 定义颜色color时6位或8位值的区别
- BestCoder 2nd Anniversary 1001/hdu5718 Oracle
- 0713
- HDU 5720 Wool
- MAC下如何更改Mysql的密码
- dataTransfer 对象
- 关于Android的assets资源使用,以及网络间的数据传递JSON格式处理
- 更改mysql ini 拒绝访问
- 定时器的合并和变速
- HDU 5721 Palace
- Codeforces - 358D - Alyona and Strings(dp)
- C语言数值和指针(重点数组指针和指针数组)