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;
}
相关推荐
美团技术团队40 分钟前
LongCat-Flash:如何使用 SGLang 部署美团 Agentic 模型
人工智能·算法
Fanxt_Ja5 小时前
【LeetCode】算法详解#15 ---环形链表II
数据结构·算法·leetcode·链表
侃侃_天下5 小时前
最终的信号类
开发语言·c++·算法
茉莉玫瑰花茶5 小时前
算法 --- 字符串
算法
博笙困了6 小时前
AcWing学习——差分
c++·算法
NAGNIP6 小时前
认识 Unsloth 框架:大模型高效微调的利器
算法
NAGNIP6 小时前
大模型微调框架之LLaMA Factory
算法
echoarts6 小时前
Rayon Rust中的数据并行库入门教程
开发语言·其他·算法·rust
Python技术极客6 小时前
一款超好用的 Python 交互式可视化工具,强烈推荐~
算法
徐小夕6 小时前
花了一天时间,开源了一套精美且支持复杂操作的表格编辑器tablejs
前端·算法·github