hdu 5720 BestCoder 2nd Anniversary Wool 推理+一维区间的并
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5720
题意:有n(n <= 105)个数 ,每个数小于等于 1018;问在给定的[L,R]区间中,有多少个数不能与已知的n个数中的任何两个组成三角形?
思路:由三角形的边长关系移位即可得到符合关系的长度len:a[i] - a[j] +1 <= len <= a[i] + a[j] - 1;(a[i] > a[j])
易知当i固定时,j为i - 1时len符合的区间是最大的;
这就变成了O(n)的算法,求出每个区间的并即可;
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<bits/stdc++.h>
using namespace std;
#define rep0(i,l,r) for(int i = (l);i < (r);i++)
#define rep1(i,l,r) for(int i = (l);i <= (r);i++)
#define rep_0(i,r,l) for(int i = (r);i > (l);i--)
#define rep_1(i,r,l) for(int i = (r);i >= (l);i--)
#define MS0(a) memset(a,0,sizeof(a))
#define MS1(a) memset(a,-1,sizeof(a))
#define MSi(a) memset(a,0x3f,sizeof(a))
#define inf 0x3f3f3f3f
#define A first
#define B second
#define MK make_pair
#define esp 1e-8
#define zero(x) (((x)>0?(x):-(x))<eps)
#define bitnum(a) __builtin_popcount(a)
#define clear0 (0xFFFFFFFE)
#define mod 1000000007
typedef long long ll;
typedef pair<ll,ll> PLL;
typedef unsigned long long ull;
template<typename T>
void read1(T &m)
{
T x = 0,f = 1;char ch = getchar();
while(ch <'0' || ch >'9'){ if(ch == '-') f = -1;ch=getchar(); }
while(ch >= '0' && ch <= '9'){ x = x*10 + ch - '0';ch = getchar(); }
m = x*f;
}
template<typename T>
void read2(T &a,T &b){read1(a);read1(b);}
template<typename T>
void read3(T &a,T &b,T &c){read1(a);read1(b);read1(c);}
template<typename T>
void out(T a)
{
if(a>9) out(a/10);
putchar(a%10+'0');
}
inline ll gcd(ll a,ll b){ return b == 0? a: gcd(b,a%b); }
const int maxn = 1e5+10;
ll a[maxn];
PLL p[maxn];
int main()
{
//freopen("data.txt","r",stdin);
//freopen("out.txt","w",stdout);
int T, kase = 1;
scanf("%d",&T);
while(T--){
ll n, L, R;
read3(n,L,R);
rep1(i,1,n){
read1(a[i]);
}
sort(a+1,a+1+n);
int cnt = 0;
rep1(i,2,n){
p[cnt].A = a[i] - a[i-1] + 1;
p[cnt++].B = a[i] + a[i-1] - 1;
}
sort(p,p+cnt);
ll ans = R - L + 1;
rep0(i,0,cnt){
ll first = p[i].A, last = p[i].B;
if(first > R) break;
while(p[i+1].A <= last)
last = max(last, p[++i].B);
if(last < L) continue;
first = max(L,first), last = min(last,R);
ans -= last - first + 1;
}
printf("%I64d\n", ans);
}
return 0;
}
hdu 5720 BestCoder 2nd Anniversary Wool 推理+一维区间的并的更多相关文章
- hdu 5719 BestCoder 2nd Anniversary B Arrange 简单计数问题
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5719 题意:一个数列为1~N的排列,给定mn[1...n]和mx[1...n],问有符合的排列数为多少 ...
- BestCoder 2nd Anniversary的前两题
Oracle Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Su ...
- BestCoder 2nd Anniversary/HDU 5719 姿势
Arrange Accepts: 221 Submissions: 1401 Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 262144/2 ...
- BestCoder 2nd Anniversary/HDU 5718 高精度 模拟
Oracle Accepts: 599 Submissions: 2576 Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 262144/26 ...
- BestCoder 2nd Anniversary
A题 Oracle http://bestcoder.hdu.edu.cn/contests/contest_chineseproblem.php?cid=703&pid=1001 大数相加: ...
- BestCoder 2nd Anniversary 1001 Oracle
找到最小的非零数字拆开来相加. 高精度. #include <iostream> #include <cstdio> #include <cstring> #inc ...
- BestCoder 2nd Anniversary 1002 Arrange
排除所有不符合条件后根据当前位置上下界计算, 由于前面取的数肯定在之后的区间内,所以去掉已取的个数即可. #include <iostream> #include <cstdio&g ...
- hdu 5720(贪心+区间合并)
Wool Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Subm ...
- hdu 5311 Hidden String (BestCoder 1st Anniversary ($))(深搜)
http://acm.hdu.edu.cn/showproblem.php?pid=5311 Hidden String Time Limit: 2000/1000 MS (Java/Others) ...
随机推荐
- [Android]天气App 2 项目搭建
对于天气App,为了简化一些功能,暂时模仿MUUI系统提供的那个App. 本项目需要引入本人经常使用的一个工具库DroidTool,这个是本人根据工作中,收集到一些工具类,下载地址. ...
- 精通C#(第6版)
<精通C#(第6版)> 基本信息 原书名:Pro C# 5.0 and the .NET 4.5 framework,sixth edition 作者: (美)Andrew Troelse ...
- ionic 中使用ion-slide-box
ion-slide-box 用法: <ion-slide-box class="slide" auto-play="true" does-continue ...
- DWZ框架学习
转自(http://blog.sina.com.cn/s/blog_667ac0360102ec0q.html) 初始化配置文件 $(function(){ DWZ.init("dwz.fr ...
- hdu 4612 Warm up 桥缩点
4612Warm hdu up 题目:给出一个图,添加一条边之后,问能够在新图中得到的最少的桥的数量. 分析:我们可以双联通分量进行缩点,原图变成了一棵树.问题变成了:求树中添加一条边之后,使得不在圈 ...
- android注解[Jake Wharton Butter Knife]
Introduction Annotate fields with @InjectView and a view ID for Butter Knife to find and automatical ...
- Linux 字符设备控制技术
字符设备控制技术 一.字符设备控制理论 1.作用 大部分设备除了具有<读写设备>的能力,还应该有<控制设备>的能力.比如改变 波特率 2. 应用程序接口 在用户空间中使用 Io ...
- Table of Contents - 设计模式
设计原则 OCP - 开闭原则 SRP - 单一职责原则 DIP - 依赖倒置原则 ISP - 接口隔离原则 LSP - 里氏替换原则 LoD - 迪米特法则 创建型模式 工厂方法模式 抽象工厂模式 ...
- 手把手教你认识并搭建Nginx
手把手教你认识并搭建Nginx Nginx (“engine x”) 是一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器. Nginx 是由 Igor ...
- Git 一些错误的解决方法
Git初学者的个人经验记录,仅供参考 1. Pull is not possible because you have unmerged files. 症状:pull的时候 $ git pull Pu ...