【牛客训练记录】牛客小白月赛103

训练情况

赛后反思

C题又头铁不测极限数据直接交,导致 WA

A题

我们想要周长最小,显然选择三角形,所以我们只需要找到三根长度相同的木棍即可,存在就输出 \(3 \times i\),不存在三根一样长的木棍就是 no

#include <bits/stdc++.h>
#define int long long

using namespace std;

void solve(){
	int n; cin>>n;
	vector<int> a(n + 1);
	vector<int> cnt(103);
	for(int i = 1;i<=n;i++) cin>>a[i],cnt[a[i]]++;
	for(int i = 1;i<=100;i++){
		if(cnt[i] >= 3){
			cout<<"yes"<<endl;
			cout<<3*i<<endl;
			return;
		}
	}	
	cout<<"no"<<endl;
}

signed main(){
	int T; cin>>T; while(T--)
	solve();
	return 0;
}

B题

小模拟,注意一下细节即可

#include <bits/stdc++.h>
#define int long long

using namespace std;

void solve(){
	string s; cin>>s;
	int n = s.size();
	int pos = -1;
	for(int i = 0;i<n;i++){
		if(s[i] == '@'){
			pos = i;
			break;
		}
	}
	if(pos == -1){
		cout<<"No"<<endl;
		return;
	}
	string local = s.substr(0,pos);
	string domain = s.substr(pos + 1);
	// cout<<local<<" "<<domain<<endl;
	bool flag = true;
	if(local.size() < 1 || local.size() > 64) flag = false;
	if(domain.size() < 1 || domain.size() > 255) flag = false;
	for(int i = 0;i<local.size();i++){
		if(!((local[i] >= 'a' && local[i] <= 'z') 
			|| (local[i] >= 'A' && local[i] <= 'Z')
			|| (local[i] >= '0' && local[i] <= '9') 
			|| local[i] == '.')) flag = false;
	}
	for(int i = 0;i<domain.size();i++){
		if(!((domain[i] >= 'a' && domain[i] <= 'z') 
			|| (domain[i] >= 'A' && domain[i] <= 'Z')
			|| (domain[i] >= '0' && domain[i] <= '9'
			|| domain[i] == '.' || domain[i] == '-'))) flag = false;
	}
	if(local[0] == '.' || local[local.size() - 1] == '.'
		|| domain[0] == '.' || domain[domain.size() - 1] == '.'
		|| domain[0] == '-' || domain[domain.size() - 1] == '-') flag = false;
	if(flag) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

signed main(){
	int T; cin>>T; while(T--)
	solve();
	return 0;
}

C题

通过暴力枚举打表

#include <bits/stdc++.h>
#define int long long

using namespace std;

void solve(){
	for(int k = 1;k<=100;k++){
	int n = k;
	vector<bool> vis(1E7+1);
	for(int i = 1;i<=1E4;i++) vis[i] = 0;
	for(int i = 1;i<=n;i++){
		for(int j = 1;j<=n;j++){
			vis[i^j] = 1;
		}
	}
	for(int i = 0;i<=1E7;i++){
		if(!vis[i]){
			cout<<i<<",";
			break;
		}
	}
}
}

signed main(){
	int T; cin>>T; while(T--)
	solve();
	return 0;
}

我们容易发现后面的部分就是 \(0 \sim n-1\) 的二进制串长度,我们设二进制串的长度为 \(len\),答案是 \(2^{len}\),注意 \(\le 2\) 的情况要特判

#include <bits/stdc++.h>
#define int long long

using namespace std;

void solve(){
	int n; cin>>n;
	if(n<=2){
		cout<<1<<endl;
		return;
	}
	n--;
	int ans = 0;
	while(n){
		ans++;
		n/=2;
	}	
	cout<<(1ll<<ans)<<endl;
}

signed main(){
	int T; cin>>T; while(T--)
	solve();
	return 0;
}
posted @ 2024-10-25 21:00  MNNUACM_2024ZY  阅读(24)  评论(0编辑  收藏  举报