当前位置: 首页> 科技> 能源 > 找学校的网站_软件开发培训课程咨询_刷钻业务推广网站_专业seo培训

找学校的网站_软件开发培训课程咨询_刷钻业务推广网站_专业seo培训

时间:2025/7/11 15:18:21来源:https://blog.csdn.net/2401_85714312/article/details/146611401 浏览次数:0次
找学校的网站_软件开发培训课程咨询_刷钻业务推广网站_专业seo培训

蓝桥刷题

3227

找到最多的数
方法一:摩尔投票法
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main()
{
  int n,m;
  cin>>n>>m;
  int a[m*n];
  for(int i=0;i<n*m;i++)
  {

    cin>>a[i];
  }
  int cand=-1,vote=0;
  for(auto num:a)
  {
    if(vote==0)
    {
      cand=num;
    }
    if(cand==num)
    {
      vote++;
    }
    else
    {
      vote--;
    }
 
  }
  cout<<cand;
  return 0;
}


方法二:sort()快排法

#include <bits/stdc++.h>
using namespace std;
int a[1000005];
#define int long long
signed main()
{
  int n,m;
  cin>>n>>m;
  for(int i=0;i<n*m;i++)
  {

    cin>>a[i];
  }
  sort(a,a+(n*m));
  int nums=a[n*m/2];
  cout<<nums;
  return 0;
}


1372.
美丽的区间

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=10000005;
int a[N];
signed main()
{
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n,k;
  int ans=1000000005;
  cin>>n>>k;
  for(int i=1;i<=n;i++)
  {
    cin>>a[i];
  }
  int sum=0;
  for(int l=0,r=1;l<n;l++)
  {
   while(r<=n&&sum<k)
   {
     sum+=a[r];
     r++;
   }
   if(sum>=k){ans=min(ans,r-l);}
   sum-=a[l];
  }
  if(ans==1000000005)
  {
    cout<<0;
  }
  else{
cout<<ans;
  }
  return 0;
}


2695.
聪明的小羊肖恩

#include<bits/stdc++.h>
using namespace std;
#define int long long 
const int N = 2000009;
int a[N];
signed main()
{
  int n , L , R ; cin >> n >> L >> R;
  for(int i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1,a + 1 + n);
  int  res = 0;
  for(int i = 1; i <= n; i++)
  {
    int  l = L - a[i] , r = R - a[i];
    res += upper_bound(a + i + 1,a + 1 + n,r) - lower_bound(a + i + 1,a + 1 + n,l);
  }
  cout << res << endl;
  return 0;
}

关键字:找学校的网站_软件开发培训课程咨询_刷钻业务推广网站_专业seo培训

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: