hdu 5720 - Wool (线段交的长度)
来源:互联网 发布:淘宝装修设计 编辑:程序博客网 时间:2024/05/14 04:43
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 <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>#include <bits/stdc++.h>#include <stack>#define LL long longusing namespace std;#define For(i,j,n) for(int i=j;i<=n;i++)#define mst(ss,b) memset(ss,b,sizeof(ss));const int N=1200000;const LL mod=998244353;int T;int n,m;int len;LL ll,rr;LL a[1200000];int b[1200000];LL r[120000000];LL l[120000000];bool cmp(LL x,LL b){ return x>b;}bool can(LL li,LL ri){ LL t=max(li,ll); LL u=min(ri,rr); if(t>u) return false; return true;}bool cmp2(int x,int y){ return l[x]<l[y];}int main(){ scanf("%d",&T); while(T--) { scanf("%d%I64d%I64d",&n,&ll,&rr); for(int i=0;i<n;i++) scanf("%I64d",&a[i]); sort(a,a+n,cmp); int cnt=0; for(int i=0;i<n;i++) { r[i] = a[i] + a[i+1] -1; l[i] = a[i] - a[i+1] +1; if(can(l[i],r[i])) { b[cnt++]=i } } sort(b,b+cnt,cmp2); LL low,high; LL ans=0; for(int i=0;i<cnt;i++) { int j; low = l[b[i]]; high = r[b[i]]; for(j=i+1;j<cnt;j++) { if(l[b[j]]<=high) { high = max(high,r[b[j]]); } else break } if(low <=ll) low=ll; if(high>= rr) high=rr; ans = ans + high - low + 1; i=j-1; } printf("%I64d\n",rr-ll+1 - ans); } return 0;}
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(贪心,扫描线,区间合并)
- HDU 5720 Wool BestCoder 2nd Anniversary (区间覆盖)
- HDU-5700-区间交(线段树)
- hdu 5700 区间交(线段树)
- hdu 1542 矩形交(线段树)
- HDU 1086(线段判交)
- HDU 1255 覆盖的面积(线段树扫描线求面积的交)
- UVALive 6092 - Catching Shade in Flatland(线段和圆交线段最大长度)
- 给RecyclerView 添加HeadView
- 二分法(binary search)
- poj——3259——Wormholes
- 【HDU5725 2016 Multi-University Training Contest 1C】【最短路 曼哈顿距离+贪心 前缀和】Game 有特殊守卫地图中所有空格点的最短路之和
- WEB 前端切图更友好的兼容Retina屏幕
- hdu 5720 - Wool (线段交的长度)
- Oracle之故障处理:解决“ora-01652无法扩展temp段”问题
- Android:学习AIDL,这一篇文章就够了(上)
- undefined reference to 'pthread_create'
- 图片压缩算法
- ssh 模板
- 3d Touch基本应用
- iOS开发——创建你自己的Framework
- 【HDU5726 2016 Multi-University Training Contest 1D】【gcd的下降性质 STL-map】GCD 多少段区间gcd等于给定区间gcd