hdu-5720 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≤10^5,1≤L≤R≤10^18).
The second line contains n integers, the i-th integer denotes ai (1≤ai≤10^18).
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map> using namespace std; #define For(i,j,n) for(int i=j;i<=n;i++)
#define mst(ss,b) memset(ss,b,sizeof(ss)); typedef long long LL; template<class T> void read(T&num) {
char CH; bool F=false;
for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
F && (num=-num);
}
int stk[70], tp;
template<class T> inline void print(T p) {
if(!p) { puts("0"); return; }
while(p) stk[++ tp] = p%10, p/=10;
while(tp) putchar(stk[tp--] + '0');
putchar('\n');
} const LL mod=998244353;
const double PI=acos(-1.0);
const int inf=1e9;
const int N=1e5+10;
const int maxn=1e3+10;
const double eps=1e-6; int n;
LL l,r,a[N];
struct node
{
LL l,r;
}po[N];
int cmp(node x,node y)
{
if(x.l==y.l)return x.r<y.r;
return x.l<y.l;
}
int vis[N];
int main()
{
int t;
read(t);
while(t--)
{
mst(vis,0);
read(n);read(l);read(r);
For(i,0,n-1)read(a[i]);
sort(a,a+n);
For(i,1,n-1)
{
po[i].r=a[i]+a[i-1]-1;
po[i].l=a[i]-a[i-1]+1;
}
sort(po+1,po+n,cmp);
LL len=0;
For(i,1,n-1)
{
if(i==n-1)continue;
if(po[i].r<po[i+1].l)continue;
else
{
po[i+1].l=po[i].l;
po[i+1].r=max(po[i].r,po[i+1].r);
vis[i]=1;
}
}
For(i,1,n)
{
if(!vis[i])
{
if(po[i].l>r||po[i].r<l||po[i].l>po[i].r)continue;
LL L=max(po[i].l,l),R=min(po[i].r,r);
len=len+(R-L+1);
}
}
cout<<r-l+1-len<<"\n";
} return 0;
}
hdu-5720 Wool(区间并+扫描线)的更多相关文章
- hdu 5720 Wool
hdu 5720 问题描述 黎明时,Venus为Psyche定下了第二个任务.她要渡过河,收集对岸绵羊身上的金羊毛. 那些绵羊狂野不驯,所以Psyche一直往地上丢树枝来把它们吓走.地上现在有n n ...
- hdu 5720(贪心+区间合并)
Wool Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Subm ...
- HDU 5726 GCD 区间GCD=k的个数
GCD Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submis ...
- hdu 5720 BestCoder 2nd Anniversary Wool 推理+一维区间的并
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5720 题意:有n(n <= 105)个数 ,每个数小于等于 1018:问在给定的[L,R]区间中 ...
- HDU 1542 - Atlantis - [线段树+扫描线]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1542 Time Limit: 2000/1000 MS (Java/Others) Memory Li ...
- hdu 3642 Get The Treasury(扫描线)
pid=3642" style="">题目链接:hdu 3642 Get The Treasury 题目大意:三维坐标系,给定若干的长方体,问说有多少位置被覆盖3次 ...
- cf1108e 线段树区间更新+扫描线
/* 有点像扫描线 思路:从左到右枚举每个点,枚举到点i时,把所有以i为起点的区间的影响删去 再加上以i-1为结尾的区间的影响 */ #include<bits/stdc++.h> usi ...
- HDU 6127 Hard challenge(扫描线)
http://acm.hdu.edu.cn/showproblem.php?pid=6127 题意: 有n个点,每个点有一个$(x,y)$坐标和一个权值,任意两点之间都有连线,并且连线的权值为两个顶点 ...
- hdu 1556(线段树之扫描线)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1556 Color the ball Time Limit: 9000/3000 MS (Java/Ot ...
随机推荐
- Linux系统下rz/sz工具的安装
(1)编译安装 root 账号登陆后,依次执行以下命令: wget http://www.ohse.de/uwe/releases/lrzsz-0.12.20.tar.gz tar zxvf lrzs ...
- kail Linux 安装Parallels Tools
网上好多都是Parallels8的 针对Parallels 9 的还真不好找..... 自己捣鼓了一阵 终于可以安装了,但还是有错误,因为公司网络太不给力....回家再测试吧 1.在桌面新建一个文件夹 ...
- LR(1)文法分析器 //c++ 实现
1.先读入终结符,非终结符,和所有产生式. 2.预处理:初始化:getpp()获得每个非终结符在产生式左边时的产生式编号, 记录在 string getp[]中(可以多个). 3.获得所有的符号的fi ...
- Codeforces Gym 100286J Javanese Cryptoanalysis 傻逼暴力
原题地址:http://codeforces.com/gym/100286/attachments/download/2013/20082009-acmicpc-northeastern-europe ...
- bzoj 5216: [Lydsy2017省队十连测]公路建设
5216: [Lydsy2017省队十连测]公路建设 Time Limit: 20 Sec Memory Limit: 512 MBSubmit: 66 Solved: 37[Submit][St ...
- css可见性
overflow:hidden: 溢出隐藏 visibility:hidden: 隐藏元素,隐藏之后还占据原来的位置 display:none: 隐藏元 ...
- 网络安全(超级详细)零基础带你一步一步走进缓冲区溢出漏洞和shellcode编写!
零基础带你走进缓冲区溢出,编写shellcode. 写在前面的话:本人是以一个零基础者角度来带着大家去理解缓冲区溢出漏洞,当然如果你是开发者更好. 注:如果有转载请注明出处!创作不易.谢谢合作. 0. ...
- IOS界面调试神器DCIntrospect
对于使用代码来写UI的同志,使用DCIntrospect来查看元素信息调整布局,再也不用凭眼睛来估了,先来看看截图 DCIntrospect是github上的开源项目:下载源码 大概介绍下用法: DC ...
- 【RESTful】1.理解REST和RESTful
简记:一套设计良好的RESTful可以帮助互联网产品支持[单个服务端+多个客户端]的场景!!!
- webrtc初探
0.闲来无事,想研究webrtc,看了一些网上的文章之后,觉得谬误较多,以讹传讹的比较多,自己试验了一把,记录一下. 官网的写的教程在实践中也觉得不用那么复杂,有种落伍与繁冗的感觉. 1.我想看的是w ...