hdu 5720

问题描述
黎明时,Venus为Psyche定下了第二个任务。她要渡过河,收集对岸绵羊身上的金羊毛。

那些绵羊狂野不驯,所以Psyche一直往地上丢树枝来把它们吓走。地上现在有n n n根树枝,第i i i根树枝的长度是ai a_i a​i​​.

如果她丢的下一根树枝可以和某两根树枝形成三角形,绵羊就会被激怒而袭击她。

现在Psyche手中只有长度不小于L L L且不大于R R R的树枝。请你帮忙计算,她下一根可以丢多少种不同长度的树枝而不会把绵羊激怒呢?
输入描述
第一行,一个整数T(1≤T≤10) T  (1 \le T \le 10) T(1≤T≤10),代表数据组数。

对于每组数据,第一行有三个整数n,L,R n,L,R n,L,R (2≤n≤105,1≤L≤R≤1018) (2 \le n \le 10 ^ 5, 1 \le L \le R \le 10 ^ {18}) (2≤n≤10​5​​,1≤L≤R≤10​18​​)。

第二行,n n n个整数,第i i i个整数为ai a_i a​i​​ (1≤ai≤1018) (1 \le a_i \le 10 ^ {18}) (1≤a​i​​≤10​18​​),代表第i i i根树枝的长度。
输出描述
输出T T T行,对于每组数据,输出选取方式总数。
输入样例
2
2 1 3
1 1
4 3 10
1 1 2 4
输出样例
2
5
Hint
对于第一组数据,可以选用长度为2,3 2, 3 2,3的树枝。

对于第二组数据,可以选用长度为6,7,8,9,10 6, 7, 8, 9, 10 6,7,8,9,10的树枝。

一般懒得解释题意就直接放题目!
首先关于三角形的三边判断是任意一边要小于另外两边的和大于另外两边的差,所以就是找出范围就好。将地上的枝条排序,只要求出相邻的两两边的长度限制的范围就好,因为其他任意两两边的范围会被这个所包括
然后将这些范围去重,形成几个互不相交的区间范围,然后用总的范围一个一个减去就好(当然,减得时候要判断这些范围与总的范围的相交
 #include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std; typedef long long ll;
const int M = 1e5 + ;
ll a[M]; struct node{
bool dis;
ll l,r;
}b[M],c[M]; bool cmp(node a,node b){return a.l<b.l;} bool judge(ll a,ll b,ll c)
{
if (a>=b&&a<=c) return true;
return false;
} int main()
{
int t,n;
ll l,r;
scanf("%d",&t);
while (t--)
{
scanf("%d%I64d%I64d",&n,&l,&r);
for (int i= ; i<=n ; i++)
scanf("%I64d",&a[i]);
sort(a+,a+n+);
int ans=;
for (int i= ; i<=n ; i++)
{
b[++ans].l=a[i]-a[i-]+;
b[ans].dis=false;
b[ans].r=a[i]+a[i-]-;
b[ans].dis=true;
}
sort(b+,b+ans,cmp);
int cas=;c[++cas].l=b[].l;c[cas].r=b[].r;
for (int i= ; i<=ans ; i++){
if (judge(b[i].l,c[cas].l,c[cas].r)){
if (!judge(b[i].r,c[cas].l,c[cas].r))
c[cas].r=b[i].r;
}
else{
c[++cas].l=b[i].l;c[cas].r=b[i].r;
}
}
ll res=r-l+;
for (int i= ; i<=cas ; i++){
if (judge(c[i].l,l,r)){
if (judge(c[i].r,l,r))
res-=(c[i].r-c[i].l+);
else
res-=(r-c[i].l+);
}
else {
if (c[i].l<l){
if (judge(c[i].r,l,r))
res-=(c[i].r-l+);
else if (c[i].r>r)
res-=(r-l+);
}
}
}
if (res<) res=;
printf("%I64d\n",res);
}
return ;
}

关系)

hdu 5720 Wool的更多相关文章

  1. hdu 5720 BestCoder 2nd Anniversary Wool 推理+一维区间的并

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5720 题意:有n(n <= 105)个数 ,每个数小于等于 1018:问在给定的[L,R]区间中 ...

  2. hdu 5920 Wool 思路

    Wool Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Problem D ...

  3. hdu 5720(贪心+区间合并)

    Wool Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Subm ...

  4. hdu 5720

    考虑三个树枝:a,b,c若c是将要抛出的树枝,那么形成三角形的条件是a+b>c and a-b<c 可以写成 c属于开区间(a-b,a+b)对于每个C和许许多多的其他边,如何保证C不构成三 ...

  5. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  6. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  7. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  8. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  9. HDU 4006The kth great number(K大数 +小顶堆)

    The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64 ...

随机推荐

  1. nodejs项目在webstorm里进行debug的设定

    菜单 > Run > Edit Configurations... 菜单 > Run > Debug... 菜单 > Run > Edit Configuratio ...

  2. Application Loader上传app程序

    提示:如果您安装了XCode开发环境.在/Applications/XCode.app/Contents/Applications目录中可以找到Application Loader(右键XCode选择 ...

  3. ADF_Starting系列9_使用EJB/JPA/JSF通过ADF构建Web应用程序之测试J2EE Container

    2013-05-01 Created By BaoXinjian

  4. jquery判断复选框checkbox是否被选中

    jquery判断复选框checkbox是否被选中 使用is方法 //如果选中返回true //如果未选中返回false .is(':checked');

  5. DirectBuffer

    1.如何分配,分配是哪里的内存 ByteBuffer.allocateDirect()来分配(ByteBuffer.allocate()分配堆内内存),分配的是非Heap(堆外)的内存,不排除操作系统 ...

  6. 【转】C#环形队列

    概述 看了一个数据结构的教程,是用C++写的,可自己C#还是一个菜鸟,更别说C++了,但还是大胆尝试用C#将其中的环形队列的实现写出来,先上代码: 1 public class MyQueue< ...

  7. ios系统的中arm指令集

    arm结构处理器,几乎所有的手机都基于arm,其在嵌入式系统中应用非常广泛. ARM 处理器因为低功耗和小尺寸而闻名,它的性能在同等功耗的产品中也很出色.这里我们注意一点,模拟器并不运行arm代码,软 ...

  8. UBUNTU 13.04 install Grive

    sudo apt-get install software-properties-common sudo apt-get install python-software-properties sudo ...

  9. Libevent库 编译与使用

    Libevent官网:http://libevent.org/ windows 7下编译: 编译环境: windows 7 + VS2010 (1)解压libevent到F:\libevent\lib ...

  10. libssh2 的集成与应用

    http://blog.csdn.net/wyc6668205/article/details/9179197 Xmanager Enterprise 4 putty 等工具都功能都是利用libssh ...