hdu 5920 Wool 思路
Wool
Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
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.
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).
2 1 3
1 1
4 3 10
1 1 2 4
5
In the first example, $ 2, 3 $ are available.
In the second example, $ 6, 7, 8, 9, 10 $ are available.
#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 思路的更多相关文章
- D - Ugly Problem HDU - 5920
D - Ugly Problem HDU - 5920 Everyone hates ugly problems. You are given a positive integer. You must ...
- HDU 5920 Ugly Problem 【模拟】 (2016中国大学生程序设计竞赛(长春))
Ugly Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tota ...
- HDU - 5920 Ugly Problem 求解第一个小于n的回文数
http://acm.hdu.edu.cn/showproblem.php?pid=5920 http://www.cnblogs.com/xudong-bupt/p/4015226.html 把前半 ...
- HDU 5920 Ugly Problem 高精度减法大模拟 ---2016CCPC长春区域现场赛
题目链接 题意:给定一个很大的数,把他们分为数个回文数的和,分的个数不超过50个,输出个数并输出每个数,special judge. 题解:现场赛的时候很快想出来了思路,把这个数从中间分为两部分,当位 ...
- hdu 5720 Wool
hdu 5720 问题描述 黎明时,Venus为Psyche定下了第二个任务.她要渡过河,收集对岸绵羊身上的金羊毛. 那些绵羊狂野不驯,所以Psyche一直往地上丢树枝来把它们吓走.地上现在有n n ...
- hdu 5920(模拟)
Ugly Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tota ...
- hdu 5701(区间查询思路题)
中位数计数 Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Subm ...
- hdu 5181 numbers——思路+区间DP
题目:http://acm.hdu.edu.cn/showproblem.php?pid=5181 题解:https://www.cnblogs.com/Miracevin/p/10960717.ht ...
- hdu 4698 - Counting(思路)
转:题意:给定一个二维平面,其中x取值为1-N,y取值为1-M,现给定K个点,问至少包括K个点中的一个的满足要求的<Xmin, Xmax, Ymin, Ymax>共有多少中取值情况.也就是 ...
随机推荐
- 网络模型+三次握手+四次挥手+DNS+HTTPS
网络模型+三次握手+四次挥手+DNS+HTTPS 这篇文章十分精华,所以整理一下: 一.网络模型 OSI七层模型,和TCP/IP五层模型(更为普遍) TCP/IP 协议集: 二.TCP协议(传输层)建 ...
- xmapp开启https
在开发微信小程序的时候我们需要开启https本地测试,以下我们说明使用xmapp如何开启https访问 1. php中开启ssl 在php的配置文件中把openssl前面的注释去掉, 大概在配置文件的 ...
- etcd跨机房部署方案
使用ETCD做为元数据方便快捷,但是谈到跨机房灾备可能就迷糊了,我们在做节日灾备的时候同样遇到了问题, 通过查阅官方文档找到了解决方案,官方提供make-mirror方法,提供数据镜像服务 注意: m ...
- php 代替 js实现自定义时间选择器
w 0-php来结合服务端数据,处理前端页面的交互: 1-php 加法 乘法的效率对比,对算术运算的优化. 减少乘法运算? function w_select($wname, $wii) { $w = ...
- 【python】-- 类的创建、__new__、__metaclass___
类的创建 前面的随笔都是关于类的知识,通过类创建对象,那这个类到底是怎么产生的呢? 1. 传统创建类 class Foo(object): def __init__(self,name): self. ...
- chrome命令
chrome://settings(设置) chrome://extensions(扩展程序) chrome://history(历史记录) chrome://settings/clearBrowse ...
- 用户登录失败,该用户与可信SQL Server连接无关联,错误:18452
安装好SQLServer2005(或者装了Visual Studio 2008后自带的SQLServer2005)用SQL Server身份验证的登录的时候有时候会发生这种情况: 这样的错误的原因是: ...
- HTML中的SEO和HTML语义化
SEO 1) <title>网站SEO标题</title>, 百度搜索出来的记录, 其标题基本就提取至网站的title, 标签, 因此标题起的好, 不论对点击率还是SEO都至关 ...
- Delphi 正则表达式语法(10): 选项
Delphi 正则表达式语法(10): 选项 // preCaseLess: 不区分大小写, 相当于其他语言中的 i var reg: TPerlRegEx; begin reg := TPe ...
- Xamrin开发安卓笔记(三)
http://www.cnblogs.com/minCS/p/4118170.html Xamrin开发安卓笔记(三) 安装片 Xamrin开发安卓笔记(一) Xamrin开发安卓笔记(二) 这次 ...