CF 1529B. Sifid and Strange Subsequences
生活随笔
收集整理的這篇文章主要介紹了
CF 1529B. Sifid and Strange Subsequences
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
CF 1529B. Sifid and Strange Subsequences
題意:
給你n個數(shù),讓你從這n個數(shù)中找m個數(shù),保證這m個數(shù)中任意兩個數(shù)的差的絕對值大于等于這m個數(shù)中最大值。求一個最大的m。
題解:
這個m個數(shù)中最多只能有一個正數(shù)。因為任意兩個正數(shù),這兩個正數(shù)的差的絕對值絕對小于最大值。因此,只需要判斷當(dāng)有正數(shù)時,判斷這個序列中差的絕對值的最小值是否大于等于這個最小的正數(shù),滿足就+1
代碼:
#include<stdio.h> #include<string.h> #include<math.h> #include<stdlib.h> #include<iostream> #include<algorithm> using namespace std; typedef long long ll; const int maxn=1e5+10; const ll inf=0x7fffffff;//ll中的最大值 const int inf1=0x3f3f3f3f;//int中的最大值 int a[maxn]; int main() {int t;scanf("%d",&t);while(t--){int n,i,j,k;scanf("%d",&n);for(i=1; i<=n; i++)scanf("%d",&a[i]);sort(a+1,a+1+n);int minn=inf1;k=0;int f=0;for(i=1; i<=n; i++){if(a[i]>0){f=1;break;}k++;minn=min(minn,abs(a[i]-a[i+1]));}if(minn>=a[i]&&f)k++;printf("%d\n",k);}return 0; }總結(jié)
以上是生活随笔為你收集整理的CF 1529B. Sifid and Strange Subsequences的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: PDF文件怎么加密?推荐3种方法给你
- 下一篇: CF 1529E. Trees of T