【牛客训练记录】香港城市大学(东莞)2024新生排位赛

https://ac.nowcoder.com/acm/contest/91116#question

赛后反思

E题简单题未一次性通过,提交前没有手动测极限情况,出现了预期外的错误提交,简单题不能够大意

A题

操作1的时候增加代码行数,每次操作1、2的时候更新一下答案,操作2输出答案即可

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

using namespace std;

void solve(){
	int n,q; cin>>n>>q;
	int now = 0;
	int ans = 0;
	while(q--){
		int opt; cin>>opt;
		if(opt == 1){
			int x; cin>>x;
			now += x;
			if(now > n) now = 0,ans++;
		} else if(opt == 2){
			if(now > n) now = 0,ans++;
			cout<<ans<<endl;
		}
	}	
}

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

C题

智慧博弈题???通过手玩样例我们得到当 n 为 \([1,9]\) 的时候,答案是先手、先手、后手必胜循环,但是通过观察发现,当 \(n > 9\) 时,必胜条件与奇偶性有关,所以我们分类讨论一下即可

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

using namespace std;

void solve(){
	int x; cin>>x;
	if(x<=9){
		int pd = x%3+1;
		if(pd==2||pd==3) cout<<"Alice"<<endl;
		else cout<<"Bob"<<endl;
	} else {
		if(x&1) cout<<"Bob"<<endl;
		else cout<<"Alice"<<endl;
	}
}

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

E题

很显然,答案为四种课程人数除以30向上取整再求和,注意下cout过大的时候会变成科学计数法(大坑让我WA了一发)

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

using namespace std;

void solve(){
	int a,b,c,d; cin>>a>>b>>c>>d;
	cout<<(int)(ceil(a/30.0)+ceil(b/30.0)+ceil(c/30.0)+ceil(d/30.0))<<endl;
}

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

G题

我们通过列举出每行的方案数,最后答案根据乘法原理为每行的方案数的乘积,我们计算发现这个每行的可行方案数是一个斐波那契数列 \([1,2,3,5,8,13]\) 这种,最后我们递推求斐波那契数列再对前 \(n\) 项求积即可

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

using namespace std;

const int mod = 998244353;
const int N = 1e5 + 3;

int a[N];
int ans[N];

void pre(){
	a[1] = 1;
	a[2] = 2;
	for(int i = 3;i<=N-3;i++){
		a[i] = a[i-1] + a[i-2];
		a[i] %= mod;
	}
	int now = 1;
	for(int i = 1;i<=N-3;i++){
		now*=a[i];
		now%=mod;
		ans[i] = now;
	}
}

void solve(){
	int x; cin>>x;
	cout<<ans[x]<<endl;
}

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

H题

考虑构造,我们直接构造最后异或和为 \(n\) 即可,\(n\) 一定是 \(n\) 的因数,对于长度为奇数的情况,我们前 \(n-1\) 项相同都构造为 \(1\),第 \(n\) 项为 \(n\) 即可,对于长度为偶数的情况,我们前 \(n-2\) 项都构造为 \(2\),第 \(n-1\) 项构造为 \(1\),第 \(n\) 项构造为 \(1 \xor n\) 即可

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

using namespace std;

void solve(){
	int n; cin>>n;
	if(n&1){
		for(int i = 1;i<n;i++) cout<<1<<" ";
		cout<<n<<" ";
	} else {
		for(int i = 1;i<=n-2;i++) cout<<1<<" ";
		cout<<1<<" "<<(1^n);
	}
	cout<<endl;
}

signed main(){
	int T; cin>>T; while(T--)
	solve();
	return 0;
}
posted @ 2024-09-28 17:49  MNNUACM_2024ZY  阅读(90)  评论(0)    收藏  举报