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 ...
随机推荐
- omcat 7 的domain域名配置,Tomcat 修改JSESSIONID
https://blog.csdn.net/catoop/article/details/64581325
- raspi扩展板
1.Ciseco Slice 2.Adafruit(Plate) 3.Fen的Gertboard:(详见F盘下的使用手册) 12个缓冲输入输出端口 LED状态指示灯 3个按钮开关 6个开路集成电极 1 ...
- Crypto另外两段加密解密的代码
第一段代码风格-平铺直叙: import sys from Crypto.Cipher import AES from binascii import b2a_hex, a2b_hex class p ...
- SpringBoot中mybatis的自动生成
1.在pom文件中加入自动生成的插件 <!-- mybatis generator 自动生成代码插件 --> <plugin> <groupId>org.mybat ...
- iOS 读书笔记 第一章
1.确定某个实例或类方法是否可用. 1)使用NSObject的类方法instancesRespondToSelector:来确定是否在该类的一个实例中存在一个特定的选择器. NSArray *arra ...
- vSphere 6.5 新功能 (7) - 支持 512e 硬盘
2016-12-11 Newton 长期以来,机械硬盘在储存数据时,一直都是以 512 byte 大小的扇区(Sector)为单位分割进行读写.随着硬盘容量的不断提升,这种古老的分配标准已经越来越不合 ...
- cart树剪枝
当前子树的损失函数: $C_a(T) = C(T) + a|T|$, 其中$C(T)$为对训练数据的预测误差,$|T|$为树的叶子结点数目,反映模型的复杂度.对固定的$a$,一定存在使损失函数$C_a ...
- mmall 项目实战(一)项目初始化
1.创建 数据库 及 表 数据脚本: /* Navicat Premium Data Transfer Source Server : 182.92.82.103 Source Server Type ...
- Java 实现原型(Prototype)模式
public class BaseSpoon implements Cloneable {//spoon 匙, 调羹 String name; public String getName() { re ...
- 2015 Multi-University Training Contest 3--1011 Work
代码: #include<cstdio> #include<cstring> using namespace std; int n,k; int father[105],son ...