ZJYC2023 浙江省大学生程序设计竞赛校内选拔赛部分题解 C J B L

ZJYC2023 浙江省大学生程序设计竞赛校内选拔赛部分题解 C J B L

难度分布:

签到:CJ
Easy:BL
Midium:IAGKFE
Hard:DH


题解:

签到:CJ

C - ^{-1}

参考代码:

#include<bits/stdc++.h>
using namespace std;
#define int long long 
signed main(){
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		int x;
		cin>>x;
		if(x==m){
			cout<<i<<endl;
			return 0;
		} 
	}
	return 0;
}

J - Climbing Takahashi

参考代码:

#include<bits/stdc++.h>
using namespace std;
#define int long long 
signed main(){
	int n;
	cin>>n;
	int last=0;
	for(int i=1;i<=n;i++){
		int x;
		cin>>x;
		if(x>last){
			last=x;
		}else break;
	}
	cout<<last<<endl;
	return 0;
}

Easy:BL

B - Enlarged Checker Board

思路: 模拟

参考代码:

#include<bits/stdc++.h>
using namespace std;
#define int long long 
signed main(){
	int n,a,b;
	cin>>n>>a>>b;
	int ok = 0;
	for(int i=1;i<=n;i++){
		for(int k=1;k<=a;k++){
			for(int j=1;j<=b*n;j++){
				int now=(j+b-1)/b;
				if((now+ok)%2)cout<<'.';
				else cout<<'#';	
			}
			cout<<endl;
		}
		ok++;
	}
	return 0;
}

L - Swappable

思路:由于要找到两两不相同的个数, O ( n 2 ) O(n^2) O(n2) 暴力会超时,所以使用 m a p map map 计数,枚举 1 − n 1-n 1n 每次获得与当前位不相同的个数为前 i − 1 i-1 i1 个数减去前 i − 1 i-1 i1 个数中 a [ i ] a[i] a[i] 出现的次数,这个用 m a p map map 实现即可。

参考代码:

#include<bits/stdc++.h>
using namespace std;
#define int long long 
signed main(){
	map<int,int>mp;
	int n;
	cin>>n;
	int ans=0;
	for(int i=1;i<=n;i++){
		int x;
		cin>>x;
		ans+=i-1;
		ans-=mp[x];
		mp[x]++;
	}
	cout<<ans<<endl;
	return 0;
}

根据赛时情况来看,MidiumHard 题解就不写了,若有疑问可单独私聊。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值