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 ...
随机推荐
- 2-sat问题,输出方案,几种方法(赵爽的论文染色解法+其完全改进版)浅析 / POJ3683
本文原创于 2014-02-12 09:26. 今复习之用,有新体会,故重新编辑. 2014-02-12 09:26: 2-sat之第二斩!昨天看了半天论文(赵爽的和俉昱的),终于看明白了!好激动有 ...
- HDU - 5974 A Simple Math Problem (数论 GCD)
题目描述: Given two positive integers a and b,find suitable X and Y to meet the conditions: X+Y=a Least ...
- luogu P1260 工程规划
题目描述 造一幢大楼是一项艰巨的工程,它是由n个子任务构成的,给它们分别编号1,2,…,n(5≤n≤1000).由于对一些任务的起始条件有着严格的限制,所以每个任务的起始时间T1,T2,…,Tn并不是 ...
- mysql统计功能和数据库information_schema/performance_schema
1.去重统计数据表行数: select count(distinct col_name) from table_name; 2.统计行数 select count(*) from table_name ...
- 谷歌訪问之直接输入ip地址
废话啥说.直接上IP: 173.194.121.51 173.194.43.19 173.194.65.147 74.125.235.148
- Linux C++的多线程编程(转)
1. 引言 线程(thread)技术早在60年代就被提出,但真正应用多线程到操作系统中去,是在80年代中期,solaris是这方面的佼佼者.传统的Unix也支持线程的概念,但是在一个进程(proces ...
- PHP接收参数的几种方式
PHP5在默认的情况下接收参数是需要使用 $_GET['value']; $_POST['value']; 还可以在PHP.ini 文件中的 将register_globals = Off 改re ...
- Java基础:执行时异常和非执行时异常
1.Java异常机制 Java把异常当做对象来处理,并定义一个基类java.lang.Throwable作为全部异常的超类. Java中的异常分为两大类:错误Error和异常Exception.Jav ...
- postgres源码目录结构
1.第一级目录介绍 |_postgres |_aclocal.m4------------config用的文件的一部分 |_config----------------config文件目录 |_con ...
- CodeVS2492 上帝造题的七分钟2(树状数组+并查集)
传送门 树状数组模板题.注意优化,假设某个数的值已经是1了的话.那么我们以后就不用对他进行操作了,这个能够用并查集实现. 这道题还有个坑的地方,给出查询区间端点的a,b,有可能a>b. #inc ...