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:模拟,转置得性质a[i][j] = a[j][i], 模拟一些即可

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;
}
相关推荐
VkN2X2X4b12 分钟前
算法性能的渐近与非渐近行为对比的技术9
算法
好家伙VCC17 分钟前
**神经编码新视角:用Python实现生物启发的神经信号压缩与解码算法**在人工智能飞速发展的今天
java·人工智能·python·算法
W23035765737 小时前
经典算法:最长上升子序列(LIS)深度解析 C++ 实现
开发语言·c++·算法
2401_892070988 小时前
链栈(链式栈) 超详细实现(C 语言 + 逐行精讲)
c语言·数据结构·链栈
minji...8 小时前
Linux 线程同步与互斥(三) 生产者消费者模型,基于阻塞队列的生产者消费者模型的代码实现
linux·运维·服务器·开发语言·网络·c++·算法
语戚9 小时前
力扣 968. 监控二叉树 —— 贪心 & 树形 DP 双解法递归 + 非递归全解(Java 实现)
java·算法·leetcode·贪心算法·动态规划·力扣·
skywalker_119 小时前
力扣hot100-7(接雨水),8(无重复字符的最长子串)
算法·leetcode·职场和发展
bIo7lyA8v10 小时前
算法稳定性分析中的输入扰动建模的技术9
算法
CoderCodingNo10 小时前
【GESP】C++三级真题 luogu-B4499, [GESP202603 三级] 二进制回文串
数据结构·c++·算法