2024 第五次周赛

A: 直接遍历即可

cpp 复制代码
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll, ll>PII;
const int N = 2e6 + 10;
const int MOD = 998244353;
const int INF = 0X3F3F3F3F;

int n, m;
int main()
{
	cin >> n;
	int cnt = 0;
	for(int i = 0; i <= n; i ++)
	{
		if((i ^ (2 * i) ^ (3 * i)) == 0) cnt ++;
	}
	cout << cnt << endl;
	return 0;
}

B:模拟,转置得性质aij = aji, 模拟一些即可

cpp 复制代码
#include <iostream>
using namespace std; 
int main() 
{
	int m,n;
	int a[501][501];
	int i,j;
	
	cin>>m>>n;//输入矩阵列数、行数
	
	for(i=1;i<=m;i++)//输入矩阵
		for(j=1;j<=n;j++)
			cin>>a[i][j];
	cout << n << " " << m << endl;
	for(i=1;i<=n;i++)//输出转至后的矩阵
	{
		for(j=1;j<=m;j++)
			cout<<a[j][i]<<" ";
		cout<<endl;
	}
	return 0;
}

C:二分枚举这个最大得距离,然后for循环遍历这些隔间之间得距离差,最后枚举出来即可:

cpp 复制代码
#include<iostream>
#include<algorithm>
using namespace std;

const int N = 1e5 + 10;
typedef long long ll;
int n, c;
int a[N];

bool check(int x)
{
	int cnt = 1, mins = a[1];
	for(int i = 2; i <= n; i ++)
	{
		if(a[i] - mins >= x)
		{
			cnt ++;
			mins = a[i];
		}
	}
	if(cnt >= c) return true;//说明安排的距离小
	else return false;// 说明安排的距离大
}
int main()
{
	cin >> n >> c;
	for(int i = 1; i <= n; i ++)
	{
		cin >> a[i];
	}
	//二分前都需要排序
	sort(a + 1, a + 1 + n);
	int l = 0, r = a[n] - a[1] + 1;
	while(l + 1 != r)
	{
		int mid = l + r >> 1;
		if(check(mid)) l = mid;
		else r = mid;
	}
	cout << l << endl;
	return 0;
}

D:shishan模拟,根据题意模拟即可,不要求思维含量:

cpp 复制代码
#include<iostream>
using namespace std;
#include<algorithm>
string yw[30]={"","one","two","three","four","five","six","seven",
	"eight","nine","ten","elven","twelve","thirteen","fourteen","fifteen",
	"sixteen","seventeen","eighteen","nineteen","twenty","a","both",
	"another","first","second","third"}; 
int sz[30]={0,1,4,9,16,25,36,49,64,81,0,21,44,69,96,25,56,89,24,61,0,
	1,4,1,1,4,9};
int k;
int a[10];

int main()
{
    for(int i=1;i<=6;i++){
		string x;
		cin>>x;
		for(int j=1;j<=26;j++){
			if(yw[j]==x){
				a[++k]=sz[j];break;
			}
		}
	}
	if(k==0){cout<<0<<endl;return 0;}
	sort(a+1,a+k+1);
	for(int i=1;i<=k;i++){
	if(i!=1&&a[i]<10)cout<<0;
		cout<<a[i];
	}
	cout<<endl;
	return 0;
}

E:

cpp 复制代码
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int ,int>PII;
const ll N = 3e5 + 5,M = 3e5;
const ll mod = 1e9 + 7;
ll n , a, b, ni[N];
ll kmi(ll a, ll b)
{
	ll res = 1;
	while(b){
		if(b & 1){
			res = res * a % mod;
			
		}
		a = a * a % mod;
		b >>= 1;
	}
	return res;
}
ll C(ll n , ll m)
{
	ll ans = 1;
	for(int i = 1;i <= m;i ++)
	{
		ans = ans * (n - m + i) % mod * ni[i]%mod;
	}
	return ans;
}
int main(){
	cin >> n >> a >> b;
	for(int i = 1;i <= M;i ++)ni[i] = kmi(i,mod - 2);
	ll ans = (kmi(2, n) - C(n ,a) - C(n, b) - 1 + 3 * mod)%mod;
	printf("%lld",ans);
	return 0;
}
相关推荐
Jerry3 小时前
LeetCode 101. 对称二叉树
算法
可编程芯片开发4 小时前
基于MPPT最大功率跟踪的离网光伏发电系统Simulink建模与仿真
算法
AI科技星4 小时前
线性算子不是空间映射函数,是全域双螺旋场之间拉伸、旋转、耦合、坍缩的跨空间标准化变换载体《全域数学vs传统数学:人类文明进阶200讲》第80讲
线性代数·算法·矩阵·数据挖掘·回归·乖乖数学·全域数学
米罗篮4 小时前
矩阵快速幂 (Exponentiation By Squaring Applied To Matrices)
c++·线性代数·算法·矩阵
dream_home84074 小时前
图像算法模型NPU适配与算法服务实战指南
人工智能·python·算法·npu 图像服务
大鱼>5 小时前
多宠物家庭智能管理平台:云端架构与多设备协同实战
python·算法·iot·宠物
To_OC6 小时前
LC 22 括号生成:刷完这道题,我终于搞懂回溯剪枝了
javascript·算法·leetcode
To_OC6 小时前
LC 39 组合总和:回溯入门必刷题,我踩过的两个坑都在这了
javascript·算法·leetcode
数字杂技师6 小时前
每条推荐都很准,为什么我还是越刷越无聊?
算法
兰令水6 小时前
hot100【acm版】【2026.7.14打卡-java版本】
java·数据结构·算法·leetcode·面试