A sequence (b1,b2,…,bk) is called strange, if the absolute difference between any pair of its elements is greater than or equal to the maximum element in the sequence. Formally speaking, it’s strange if for every pair (i,j) with 1≤i<j≤k, we have |ai−aj|≥MAX, where MAX is the largest element of the sequence. In particular, any sequence of length at most 1 is strange.

For example, the sequences (−2021,−1,−1,−1) and (−1,0,1) are strange, but (3,0,1) is not, because |0−1|<3.

Sifid has an array a of n integers. Sifid likes everything big, so among all the strange subsequences of a, he wants to find the length of the longest one. Can you help him?

A sequence c is a subsequence of an array d if c can be obtained from d by deletion of several (possibly, zero or all) elements.

Input
The first line contains an integer t (1≤t≤104) — the number of test cases. The description of the test cases follows.

The first line of each test case contains an integer n (1≤n≤105) — the length of the array a.

The second line of each test case contains n integers a1,a2,…,an (−109≤ai≤109) — the elements of the array a.

It is guaranteed that the sum of n over all test cases doesn’t exceed 105.

Output
For each test case output a single integer — the length of the longest strange subsequence of a.

Example
inputCopy
6
4
-1 -2 0 0
7
-3 4 -2 0 -4 6 1
5
0 5 -3 2 -5
3
2 3 1
4
-3 0 2 0
6
-3 -2 -1 1 1 1
outputCopy
4
5
4
1
3
4
Note
In the first test case, one of the longest strange subsequences is (a1,a2,a3,a4)
In the second test case, one of the longest strange subsequences is (a1,a3,a4,a5,a7).

In the third test case, one of the longest strange subsequences is (a1,a3,a4,a5).

In the fourth test case, one of the longest strange subsequences is (a2).

In the fifth test case, one of the longest strange subsequences is (a1,a2,a4).

我认识每一个字,就是读不懂题。
本题大意:一个符合标准的数列就是将其中任意一对数的差值的绝对值小于该数列的最大值,我们可以去掉数列中的任意元素来达到这个目的。
解法:首先如果一个数列都是负数,那么肯定会满足,所以我们根本不需要考虑负数的问题,0也是,我们只需要考虑正数,正数如果存在,那么它必须只有一个,因为如果两个正数相减永远不会比其中一个正数大,而且这个正数还不能比任意两个负数相减的差值的绝对值大。

#include<iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
long long fab(long long x)//取绝对值
{if (x < 0)return (-x);else return x;
}
int main()
{int t, n;int a[100001];int b[100001];scanf_s("%d", &t);while (t--){scanf_s("%d", &n);int ans = 0;int cnt = 0;for (int i = 1; i <= n; i++){scanf_s("%d", &a[i]);ans += a[i] <= 0;if (a[i] <= 0)b[++cnt] = a[i];}sort(b + 1, b + cnt + 1);long long temp = 10000000000;for (int i = 1; i < cnt; i++)temp = min(temp, fab(b[i] - b[i + 1]));for (int i = 1; i <= n; i++)if (a[i] > 0 && a[i] <= temp){++ans;break;}printf("%d\n", ans);}return 0;
}

return code;

Sifid and Strange Subsequences相关推荐

  1. CF 1529B. Sifid and Strange Subsequences

    CF 1529B. Sifid and Strange Subsequences 题意: 给你n个数,让你从这n个数中找m个数,保证这m个数中任意两个数的差的绝对值大于等于这m个数中最大值.求一个最大 ...

  2. B. Sifid and Strange Subsequences

    B. Sifid and Strange Subsequences A sequence (b1,b2,-,bk) is called strange, if the absolute differe ...

  3. Codeforces Round #722 (Div. 2)

    Codeforces Round #722 (Div. 2) 题号 题目 知识点 A Eshag Loves Big Arrays(题解略) 贪心 B Sifid and Strange Subseq ...

  4. 模拟退火 HDU - 2899 Strange Function

    Strange Function [ HDU - 2899 ] 题目大意: 函数 F(x) = 6x7 + 8x6 + 7x3 + 5x2 - yx, 其中x的范围是0 ≤ x ≤ 100. 输入y值 ...

  5. CF1471 D - Strange Definition(思维,分类讨论,lcm,gcd的性质,数论)

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #694 (Div. 2) D 很好的一道数论思维题 D - Str ...

  6. hdu 1548 A strange lift

    A strange lift Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Tota ...

  7. LeetCode:115. Distinct Subsequences

    题目 Given a string S and a string T, count the number of distinct subsequences of S which equals T. A ...

  8. Distinct Subsequences@LeetCode

    Distinct Subsequences 动态规划题.先用二维动态规划的思路解释下:设match是动态规划表,其中match[i][j]表示S.substring(0, i)对T.substring ...

  9. Strange Towers of Hanoi (POJ1958)

    Strange Towers of Hanoi (POJ1958) n个盘子4座塔的Hanoi问题至少需要多少步?(1<=n<=12) 分析: n盘3塔: \(d[n] = 2*d[n-1 ...

最新文章

  1. [JS] HEX颜色转换成RGBA
  2. c# BinaryFormatter 更换了命名空间反序列化遇到的问题
  3. Turbo C 3.0安装及使用说明
  4. 20162325金立清第三周作业
  5. python中typeerror是什么意思_TypeError:在Python中
  6. java.io.IOException: Server returned HTTP response code: 411 for URL
  7. 寻找不设防的无线局域网——战争驾驶全接触
  8. mysql表空间查看及创建
  9. 2.郝斌C语言笔记——优缺点
  10. 1、spss中做相关分析
  11. 编程计算并输出1 - n之间的所有数的平方和立方。其中n值由用户从键盘输入
  12. 图解图论介绍及应用(1):哥尼斯堡七桥
  13. 逆水寒能不能网页预约服务器,不是说《逆水寒》凉了吗,为什么新服预约不到1小时就满了?...
  14. 微信小程序之自定义组件的使用、介绍、案例分享
  15. GEE6:获取每年水体数据
  16. 博客 / 论坛 / 书籍 / 维基百科 参考文献类型
  17. 史上最详细的maven仓库详解
  18. 凯文·凯利斯坦福演讲 预言未来20年科技潮流
  19. 用python AI脚本自动打王者荣耀?一路奔上王者
  20. 在SNAP中用sentinel-1数据做DInSAR测量---以门源地震为例

热门文章

  1. hosts文件没生效,怎么办?
  2. 关于H3C 防火墙和交换机做端口汇聚
  3. 智慧安防解决方案-最新全套文件
  4. java 方法 多参数_需要在Java方法中传递多个(20+)参数。这样做有效吗?
  5. 我做了一个法律文库,这可能是最简洁、便捷查询法律条文的地方
  6. 斐讯N1盒子安装lnmp搭建可道云kodexplorer私有网盘教程
  7. 计算机绘图设计论文,计算机绘图软件在室内装饰设计教学中的应论文
  8. tensorflow损失函数均方误差怎么计算
  9. javafx-webview不支持indexeddb时怎么办
  10. 岭回归,Lasso回归及弹性网络回归原理及R实现