您当前的位置: 首页 > 

MangataTS

暂无认证

  • 0浏览

    0关注

    423博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

中位数切分(思维+暴力)

MangataTS 发布时间:2022-01-27 19:44:14 ,浏览量:0

题面链接

https://ac.nowcoder.com/acm/contest/23106/F

题面

在这里插入图片描述

思路

这个题可以想的很简答也可以想的很复杂,我的想法就是排序完后,每次找到中间位置,看是否大于等于m,如果是的话,我们就更新一下ans的值,然后一直找到不满足或者全部分解完,每找到一个就将末尾的元素删除,这样就能算出中位数了详情请看代码

代码
#include
using namespace std;
//----------------�Զ��岿��----------------
#define ll long long
#define mod 1000000007
#define endl "\n"
#define PII pair

int dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};

ll ksm(ll a,ll b) {
	ll ans = 1;
	for(;b;b>>=1LL) {
		if(b & 1) ans = ans * a % mod;
		a = a * a % mod;
	}
	return ans;
}

ll lowbit(ll x){return -x & x;}

const int N = 2e6+10;
//----------------�Զ��岿��----------------
int n,m,q,a[N];

int main()
{
	int t;
	scanf("%d",&t);
	while(t--){
		scanf("%d%d",&n,&m);
		for(int i = 1;i = 1){
			if(a[(1+r)>>1] >= m) r--,ans++;
			else break;
			
		}
		if(ans == 0) puts("-1");
		else printf("%d\n",ans);
	}
	
	
	return 0;
}

关注
打赏
1665836431
查看更多评论
立即登录/注册

微信扫码登录

0.0413s