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>共有多少中取值情况.也就是 ...
随机推荐
- 手动爬虫之报头及代理封装类(python3)
本人刚刚学习爬虫,见每次都需要添加报头比较繁琐,故将该过程封装为Url_ProxyHelper类,代码如下 import urllib.request as ur class Url_ProxyHel ...
- type属性对jq-post在ie、chrome、ff的兼容
w http://stackoverflow.com/questions/8834635/post-not-working-in-firefox
- Eclipse打包java工程
Eclipse打包java工程步骤如下: 1.选择预打包的工程->Export. 2.选择java->JAR file. 3.导出JAR文件设置. 这里有几个选项: Export gene ...
- Squid 缓存代理服务器的完整配置
Squid 缓存代理服务器 Squid 的作用 1.通过缓存的方式为用户提供web访问加速 2.对用户的web访问进行过滤控制 缓存代理服务器又分为普通代理服务器,透明代理服务器,和反向代理服务器. ...
- caffe使用(2)
总体流程 https://blog.csdn.net/hjimce/article/details/48933813 https://zhuanlan.zhihu.com/p/24087905 1.编 ...
- 开博第一篇,学习markdown
Markdown学习 其实之前自己也一直有记录,不过是Evernote记录,没有分享出来,最近看了一些牛人博客,觉得也应该分享出来.和别人多交流,多学习.所以花了几小时学了一下Markdown语法,现 ...
- flask-基础知识
Flask是一个基于Python开发并且依赖jinja2模板和Werkzeug WSGI服务的一个微型框架,对于Werkzeug本质是Socket服务端,其用于接收http请求并对请求进行预处理,然后 ...
- Delphi 正则表达式语法(4): 常用转义字符与 .
Delphi 正则表达式语法(4): 常用转义字符与 . // \d 匹配所有数字, 相当于 [0-9] var reg: TPerlRegEx; begin reg := TPerlRegE ...
- LifecycleProcessor not initialized - call 'refresh' before invoking lifecycle methods via the context: --异常记录
升级了JDK之后,启动应用,直接抛出此异常.网上搜罗半天,没有正确的解决方案. 然后想到了是“升级了JDK”,重新检查所有JDK相关的配置的地方,在Debug Configurations里找到启动时 ...
- List和Set区别
1. Set 接口实例存储的是无序的,不重复的数据.List 接口实例存储的是有序的,可以重复的元素. 2. Set检索效率低下,删除和插入效率高,插入和删除不会引起元素位置改变 <实现类有Ha ...