首页 > 其他分享 >CF 253B(队列上维护2个指针后移)

CF 253B(队列上维护2个指针后移)

时间:2022-10-25 11:08:44浏览次数:56  
标签:253B ans CF int 后移 output test input include


B. 实验误差



time limit per test



memory limit per test



input



output



小明做实验,测了n次结果,因为误差,这些结果不一样。

至少修改多少结果,才能使最大的结果不超过最小的结果的2倍?



Input



n (2 ≤ n ≤ 105),第二行有n个数c1, c2, ..., cn表示结果(1 ≤ ci ≤ 5000)



Output



输出一个整数,表示最小修改次数。



Sample test(s)



input



6 4 5 3 8 3 7



output



2



input



4 4 3 2 4



output



0



Note



第1个数据删除8,7,第二个数据本身就满足条件。

排序,从小到大枚举最小数,并把后指针挪向最大的不用修改的数进行统计即可。



#include<cstdio>
#include<functional>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<iostream>
using namespace std;
#define MAXN (100000+100)
int a[MAXN];
int n;
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);

scanf("%d",&n);
for (int i=1;i<=n;i++) scanf("%d",&a[i]);
sort(a+1,a+n+1);
a[n+1]=1000000;
// for (int i=1;i<=n;i++) cout<<a[i]<<' ';cout<<endl;
int t=1,ans=0;
for (int h=1;h<=n;h++)
{
while (a[h]*2>=a[t+1]) t++;
ans=max(ans,t-h+1);
}
cout<<n-ans<<endl;

}







标签:253B,ans,CF,int,后移,output,test,input,include
From: https://blog.51cto.com/u_15724837/5794133

相关文章