长沙学院2022蓝桥杯选拔赛第一场

A.楼下是签到题

题解链接

B.新物种

思路:需要考虑三种情况,第一种为本身要走的长度小于2H,那么要走的路程为2H,第二种情况为本身要走的距离大于2H且模H不为0,那么需要走实际距离/H+1个H,第三种情况为本身要走的距离模H为0,直接输出1,因为两个距离相等。

代码:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int a,b,c,d,h;
        scanf("%d%d%d%d%d",&a,&b,&c,&d,&h);
        double dis=sqrt((a-c)*(a-c)+(b-d)*(b-d));
        int z=dis;
        int x=2*h/dis;
        if(z%h==0)printf("1\n");
        else if(2*h<dis)printf("%d\n",(int)(((z/h)+1)*h/dis));
        else printf("%d\n",x);
    }
}

C.报数游戏

题解链接

D.星星序列

思路:用到了一个标记数组cnt[i],记录下每个元素出现的次数,后指针从第一位开始往后移动,
遇到重复出现次数超过k次的前指针就开始向后移动直到消除重复,遍历完整个序列即可,因为数字很大,所以需要采用map进行标记,时间复杂度为O(n)。

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e7 + 10;
inline int read() {
	int f = 1, x = 0; char ch;
	do { ch = getchar(); if (ch == '-')f = -1; } while (ch < '0' || ch>'9');
	do { x = x * 10 + ch - '0'; ch = getchar(); } while (ch >= '0' && ch <= '9');
	return f * x;
}
ll a[N], n,k;
map<ll,ll>cnt;
int main()
{
	n=read();k=read();
	for (int i = 0; i < n; i++)a[i]=read();
	int res = 1;
	for (int i = 0, j = 0; i < n && j < n; i++)
	{
		cnt[a[i]]++;
		while (cnt[a[i]]>k)cnt[a[j++]]--;
		res = max(res, i - j + 1);
	}
	printf("%d\n",res);
	return 0;
}

E.大小即数量

思路:本题共有两个情况需要考虑,一种为数字的数量本身就小于数字,需要全部删除,另一种是大于数字,则删除大于部分。同样采用map进行标记。由于本身只有1e5个数,也可直接采用数组标记,但需将大于1e5的数直接删除。

代码:

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=1e5+10;
ll a[maxn];
int n;
map<ll,ll>mm;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%lld",&a[i]);
        mm[a[i]]++;
    }
    sort(a+1,a+1+n);
    int m=unique(a+1,a+1+n)-a-1;
    ll ans=0;
    for(int i=1;i<=m;i++)
    {
        if(mm[a[i]]<a[i])ans+=mm[a[i]];
        else
        {
            ans+=mm[a[i]]-a[i];
        }
    }
    printf("%lld\n",ans);
}

F.排队

题解链接

G.蚌埠住了

题解链接

H.有毒的数学公式

题解链接

I.Mine Craft

题解链接

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值