Wool

Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)

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 are n 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.

 
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 integer n,L,R (2≤n≤105,1≤L≤R≤1018).

The second line contains n integers, the i-th integer denotes ai (1≤ai≤1018).

 
Output
For each test case, print the number of ways to throw a stick.
 
Sample Input
2
2 1 3
1 1
4 3 10
1 1 2 4
 
Sample Output
2
5

Hint

In the first example, $ 2, 3 $ are available.

In the second example, $ 6, 7, 8, 9, 10 $ are available.

思路:求出每条边的合法区间,区间合并一下,根据L,R,求ans;
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
using namespace std;
#define ll __int64
#define esp 0.00000000001
const int N=1e5+,M=1e7+,inf=1e9+;
const ll mod=;
ll a[N];
struct is
{
ll x,y;
}gg[N];
int cmp(is x,is y)
{
if(x.y!=y.y)
return x.y<y.y;
return x.x<y.x;
}
ll check(ll x,ll y,ll l,ll r)
{
ll maxx=max(x,l);
ll minn=min(r,y);
if(maxx<=minn)
return minn-maxx+;
return ;
}
is he(ll x,ll y,ll l,ll r)
{
is ans;
ans.x=min(x,l);
ans.y=max(r,y);
return ans;
}
int main()
{
ll x,y,z,i,t;
int T;
ll L,R;
scanf("%d",&T);
while(T--)
{
scanf("%I64d%I64d%I64d",&x,&L,&R);
for(i=;i<=x;i++)
scanf("%I64d",&a[i]);
sort(a+,a+x+);
for(i=;i<x;i++)
{
gg[i].x=a[i+]-a[i]+;
gg[i].y=a[i+]+a[i]-;
}
sort(gg+,gg+x,cmp);
int ji=;
gg[ji].x=gg[].x;
gg[ji].y=gg[].y;
ji++;
for(i=;i<x;i++)
{
if(gg[i].x<=gg[ji-].y)
{
gg[ji-]=he(gg[i].x,gg[i].y,gg[ji-].x,gg[ji-].y);
}
else
{
gg[ji].x=gg[i].x;
gg[ji].y=gg[i].y;
ji++;
}
}
ll ans=;
for(i=;i<ji;i++)
{
ans+=check(gg[i].x,gg[i].y,L,R);
}
printf("%I64d\n",R-L+-ans);
}
return ;
}

hdu 5920 Wool 思路的更多相关文章

  1. D - Ugly Problem HDU - 5920

    D - Ugly Problem HDU - 5920 Everyone hates ugly problems. You are given a positive integer. You must ...

  2. HDU 5920 Ugly Problem 【模拟】 (2016中国大学生程序设计竞赛(长春))

    Ugly Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tota ...

  3. HDU - 5920 Ugly Problem 求解第一个小于n的回文数

    http://acm.hdu.edu.cn/showproblem.php?pid=5920 http://www.cnblogs.com/xudong-bupt/p/4015226.html 把前半 ...

  4. HDU 5920 Ugly Problem 高精度减法大模拟 ---2016CCPC长春区域现场赛

    题目链接 题意:给定一个很大的数,把他们分为数个回文数的和,分的个数不超过50个,输出个数并输出每个数,special judge. 题解:现场赛的时候很快想出来了思路,把这个数从中间分为两部分,当位 ...

  5. hdu 5720 Wool

    hdu 5720 问题描述 黎明时,Venus为Psyche定下了第二个任务.她要渡过河,收集对岸绵羊身上的金羊毛. 那些绵羊狂野不驯,所以Psyche一直往地上丢树枝来把它们吓走.地上现在有n n ...

  6. hdu 5920(模拟)

    Ugly Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tota ...

  7. hdu 5701(区间查询思路题)

    中位数计数 Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Subm ...

  8. hdu 5181 numbers——思路+区间DP

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=5181 题解:https://www.cnblogs.com/Miracevin/p/10960717.ht ...

  9. hdu 4698 - Counting(思路)

    转:题意:给定一个二维平面,其中x取值为1-N,y取值为1-M,现给定K个点,问至少包括K个点中的一个的满足要求的<Xmin, Xmax, Ymin, Ymax>共有多少中取值情况.也就是 ...

随机推荐

  1. 支付宝app支付提示 系统繁忙,请稍后重试

    v2版本的支付宝支付,无论怎么调试返回的都是系统繁忙,请稍后重试提示.经过对给的示例代码的仔细研究,最后发现是由于老版本的sign_type 不加入签名计算,而新版本的支付签名它是加入签名计算的.供大 ...

  2. 第三课——SQL操作和数据类型

    [SQL分类:DDL DML DCL] 一.DDL(数据库定义语言) 定义不同的数据段.数据库.表.列.索引等数据库对象,常用语句关键字:create drop alter等 1.修改表字段,alte ...

  3. mysql_注入语句

    查看mysql中所有的用户及权限(只有root权限才能看). mysql> select distinct concat(user,host) from mysql.user; ======== ...

  4. https://blog.newrelic.com/2014/05/02/25-php-developers-follow-online/

    w https://blog.newrelic.com/2014/05/02/25-php-developers-follow-online/ 1. Rob Allen. Zend Framework ...

  5. 客户也可以申请它使用的最后一个IP地址。如果该客户所在的网络中此IP仍然可用,服务器就可以准许该申请。

    http://baike.baidu.com/item/IP地址 公有地址 公有地址(Public address)由Inter NIC(Internet Network Information Ce ...

  6. transaction 数据库事务 roolback 回滚

    事务是恢复和并发控制的基本单位 https://baike.baidu.com/item/数据库事务/9744607 事务有三种模型: 1.隐式事务是指每一条数据操作语句都自动地成为一个事务,事务的开 ...

  7. 在.NET中读取嵌入和使用资源文件的方法

    转http://www.jb51.net/article/84660.htm 本文分别介绍了使用GetManifestResourceStream读取嵌入资源,和使用. resx资源文件嵌入资源,希望 ...

  8. 删除DOM元素 parent.removeChild(target)

    p.removeChild(p.children[0]);

  9. pandas数据分析第二天

    一:汇总和计算描述统计 pandas对象拥有一组常用的数据和统计方法,用于从Series中提取单个值(sum,mean)或者从DataFrame的行或者列中提取一个Series对应的Numpy数组方法 ...

  10. SQL JOIN使用方法

    (转自W3School相关教程:http://www.w3school.com.cn,W3School是不错的在线教程,简洁高效!) 下面列出不同的SQL JOIN类型,以及他们之间的差异: JOIN ...