Good Bye 2023 题解

博客围绕多个算法问题展开。包括根据剩余序列b求原序列a及移除元素的问题,给定数的最大两个除数相关问题,数组操作博弈问题,以及寻找特定奇数长度且数字集合相同的平方数问题,并给出了部分问题的解题思路。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

A 2023

sequence a, whose product was equal to 2023, k numbers were removed, leaving a sequence b of length n. Given the resulting sequence b, find any suitable sequence a and output which k elements were removed from it, or state that such a sequence could not have existed.

Notice that you are not guaranteed that such array exists.

有解前提为 ( Π 1 n b i ) ∣ 2023 (\Pi_1^n b_i) | 2023 (Π1nbi)∣2023,加1补足剩余部分。
.

#include<bits/stdc++.h> 
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=next[p])  
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,0x3f,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define MEMx(a,b) memset(a,b,sizeof(a));
#define INF (0x3f3f3f3f)
#define F (1000000007)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int> 
#define pi pair<int,int>
#define SI(a) ((a).size())
#define Pr(kcase,ans) printf("Case #%d: %lld\n",kcase,ans);
#define PRi(a,n) For(i,n-1) cout<<a[i]<<' '; cout<<a[n]<<endl;
#define PRi2D(a,n,m) For(i,n) { \
						For(j,m-1) cout<<a[i][j]<<' ';\
						cout<<a[i][m]<<endl; \
						} 
#pragma comment(linker, "/STACK:102400000,102400000")
#define ALL(x) (x).begin(),(x).end()
#define gmax(a,b) a=max(a,b);
#define gmin(a,b) a=min(a,b);
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return ((a-b)%F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
inline int read()
{
	int x=0,f=1; char ch=getchar();
	while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
	while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();}
	return x*f;
} 
int a[1000];
void wk(){

	int n=read(),k=read();
	For(i,n) a[i]=read();
	int p=2023;
	For(i,n) {
		if(p%a[i]) {
			puts("NO");return ;
		}p/=a[i];
	}
	puts("YES");
	cout<<p;
	For(i,k-1) cout<<' '<<1;cout<<endl;
}
int main()
{
//	freopen("A.in","r",stdin);
//	freopen(".out","w",stdout);
	int T=read();
	while(T--) {
		wk();
	}
	
	
	return 0;
}


B Two Divisors

A certain number 1 ≤ x ≤ 1 0 9 1≤x≤10^9 1x109 is chosen. You are given two integers a
and b, which are the two largest divisors of the number x. At the same time, the condition 1 ≤ a < b < x 1≤a<b<x 1a<b<x is satisfied.

#include<bits/stdc++.h> 
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=next[p])  
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,0x3f,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define MEMx(a,b) memset(a,b,sizeof(a));
#define INF (0x3f3f3f3f)
#define F (1000000007)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int> 
#define pi pair<int,int>
#define SI(a) ((a).size())
#define Pr(kcase,ans) printf("Case #%d: %lld\n",kcase,ans);
#define PRi(a,n) For(i,n-1) cout<<a[i]<<' '; cout<<a[n]<<endl;
#define PRi2D(a,n,m) For(i,n) { \
						For(j,m-1) cout<<a[i][j]<<' ';\
						cout<<a[i][m]<<endl; \
						} 
#pragma comment(linker, "/STACK:102400000,102400000")
#define ALL(x) (x).begin(),(x).end()
#define gmax(a,b) a=max(a,b);
#define gmin(a,b) a=min(a,b);
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return ((a-b)%F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
inline int read()
{
	int x=0,f=1; char ch=getchar();
	while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
	while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();}
	return x*f;
} 
ll gcd(ll a,ll b){
	if(!b) return a;return gcd(b,a%b);
}
ll lcm(ll a,ll b){
	return a/gcd(a,b)*b;
}
#define MAXN (1000000+10)
int p[MAXN],tot;
bool b[MAXN]={0};
void make_prime(int n)
{
	tot=0;
	Fork(i,2,n)
	{
		if (!b[i]) p[++tot]=i;
		For(j,tot)
		{
			if (i*p[j]>n) break;
			b[i*p[j]]=1;
			if (i%p[j]==0) break;  
		}
	}
}
ll get(ll s) {
	For(i,tot) {
		if(p[i]>s) return s;
		if(s%p[i]==0) return p[i];
	}
	return s;
}
ll wk() {
	ll a=read(),b=read();
	if(a>b) swap(a,b);
	if(a==1) return b*b;
	if(b%a!=0) return lcm(a,b);
	return b*get(b);
	
}
int main()
{
//	freopen("B.in","r",stdin);
//	freopen(".out","w",stdout);
	make_prime(46342);
	int T=read();
	while(T--) {
		cout<<wk()<<endl;
	}
	
	return 0;
}


C Training Before the Olympiad

There is an array a of size n. Masha goes first, and the players take turns. Each move is described by the following sequence of actions:

If the size of the array is 1, the game ends.

he player who is currently playing chooses two different indices i, j (1≤i,j≤|a|), and performs the following operation — removes ai and aj from the array and adds to the array a number equal to ⌊ai+aj2⌋⋅2. In other words, first divides the sum of the numbers ai, aj by 2 rounding down, and then multiplies the result by 2.

Masha aims to maximize the final number, while Olya aims to minimize it. Masha and Olya decided to play on each non-empty prefix of the initial array a, and asked for your help.
For each k=1,2,…,n, answer the following question. Let only the first k elements of the array a be present in the game, with indices 1,2,…,k respectively. What number will remain at the end with optimal play by both players?

Masha一定是优先选,奇偶不同
Olya则是优先选2奇数

#include<bits/stdc++.h> 
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=next[p])  
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,0x3f,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define MEMx(a,b) memset(a,b,sizeof(a));
#define INF (0x3f3f3f3f)
#define F (1000000007)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int> 
#define pi pair<int,int>
#define SI(a) ((a).size())
#define Pr(kcase,ans) printf("Case #%d: %lld\n",kcase,ans);
#define PRi(a,n) For(i,n-1) cout<<a[i]<<' '; cout<<a[n]<<endl;
#define PRi2D(a,n,m) For(i,n) { \
						For(j,m-1) cout<<a[i][j]<<' ';\
						cout<<a[i][m]<<endl; \
						} 
#pragma comment(linker, "/STACK:102400000,102400000")
#define ALL(x) (x).begin(),(x).end()
#define gmax(a,b) a=max(a,b);
#define gmin(a,b) a=min(a,b);
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return ((a-b)%F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
inline int read()
{
	int x=0,f=1; char ch=getchar();
	while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
	while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();}
	return x*f;
} 
#define MAXN (100000+10)
ll a[MAXN]={},an[MAXN]={};
int main()
{
//	freopen("C.in","r",stdin);
//	freopen(".out","w",stdout);
	int T=read();
	while(T--) {
		int n=read();
		For(i,n) {
			a[i]=read();
		}
		int jn=0;
		ll ans=0;
		For(i,n) {
			if(a[i]%2) jn++;
			ans+=a[i];
			an[i]=ans;
			if(i==1 && jn==1) continue;
			if(jn>=3) {
				an[i]-=jn/3;
				if(jn%3==1) an[i]--;
			}
			else if(jn==1) an[i]--;
		}	
		PRi(an,n)
	}
	
	return 0;
}


D

The mathematicians of the 31st lyceum were given the following task:
You are given an odd number n, and you need to find n different numbers that are squares of integers. But it’s not that simple. Each number should have a length of n (and should not have leading zeros), and the multiset of digits of all the numbers should be the same. For example, for 234 and 432, and 11223 and 32211, the multisets of digits are the same, but for 123 and 112233, they are not.

961 , 90601 , 9006001 961,90601,9006001 961,90601,9006001等数一定是squares of integers.
n = 3 n=3 n=3时, 169 , 196 , 961 169,196,961 169,196,961是合法解。
构造出 n = k − 2 n=k-2 n=k2时,只要所有数*100,能得到 n − 2 n-2 n2个长度为 n n n的解,且末尾为2个0。
n = 3 n=3 n=3的特殊解开始,每次把上一个解末尾填2个0,再加上 " 1 " + ( n − 3 ) / 2 ∗ " 0 " + " 6 " + ( n − 3 ) / 2 ∗ " 0 " + " 9 " "1"+(n-3)/2*"0"+"6"+(n-3)/2*"0"+"9" "1"+(n3)/2"0"+"6"+(n3)/2"0"+"9", " 9 " + ( n − 3 ) / 2 ∗ " 0 " + " 6 " + ( n − 3 ) / 2 ∗ " 0 " + " 1 " "9"+(n-3)/2*"0"+"6"+(n-3)/2*"0"+"1" "9"+(n3)/2"0"+"6"+(n3)/2"0"+"1"

#include<bits/stdc++.h> 
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=next[p])  
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,0x3f,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define MEMx(a,b) memset(a,b,sizeof(a));
#define INF (0x3f3f3f3f)
#define F (1000000007)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int> 
#define pi pair<int,int>
#define SI(a) ((a).size())
#define Pr(kcase,ans) printf("Case #%d: %lld\n",kcase,ans);
#define PRi(a,n) For(i,n-1) cout<<a[i]<<' '; cout<<a[n]<<endl;
#define PRi2D(a,n,m) For(i,n) { \
						For(j,m-1) cout<<a[i][j]<<' ';\
						cout<<a[i][m]<<endl; \
						} 
#pragma comment(linker, "/STACK:102400000,102400000")
#define ALL(x) (x).begin(),(x).end()
#define gmax(a,b) a=max(a,b);
#define gmin(a,b) a=min(a,b);
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return ((a-b)%F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
inline int read()
{
	int x=0,f=1; char ch=getchar();
	while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
	while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();}
	return x*f;
} 
string s[105][105];
void pr(){
	s[1][1]="1";
	s[3][1]="169";
	s[3][2]="196";
	s[3][3]="961";
	for(int i=5;i<=99;i+=2) {
		For(j,i-2) {
			s[i][j]=s[i-2][j]+"00";
		}
		s[i][i-1]="1"+string((i-3)/2,'0')+"6"+string((i-3)/2,'0')+"9";
		s[i][i]="9"+string((i-3)/2,'0')+"6"+string((i-3)/2,'0')+"1";
	}
	
}
int main()
{
//	freopen("D.in","r",stdin);
//	freopen(".out","w",stdout);
	int T=read();
	pr();
	while(T--) {
		int p=read();
		For(i,p) {
			cout<<s[p][i]<<endl;
		}
	}
	return 0;
}


### 2023 年机器人开发者大赛题目解析 #### 问题分析 该问题是关于如何判断最少的人数在填写情况时撒谎。给定一组人的自我报告数据(是否参加比赛和是否玩游戏),以及他们的实际成功程度排序,目标是最小化不一致的数量。 对于输入中的 `N` 组数据,每组描述了一场比赛的结果,其中涉及名次 \(p\) 和杀敌数量 \(k\) 的关系。通过这些信息可以推导出可能的最小谎言人数[^1]。 --- #### 数据结构设计 为了高效处理这个问题,可采用如下方法: - **数组表示**:创建一个长度为 \(N\) 的布尔型数组来记录每个人的真实状态与其声明的一致性。 - **优先队列/堆**:如果需要按某种顺序比较,则可以用最大堆或最小堆辅助计算最优解。 以下是基于 Python 实现的一个通用算法框架[^2]: ```python def min_lies(n, data): # 初始化变量 lies_count = 0 # 对每个人的申报情况进行遍历并验证一致性 for person in range(n): actual_rank, kill_score = data[person] # 假设条件逻辑 (需根据具体业务场景调整) if not is_consistent(actual_rank, kill_score): lies_count += 1 return lies_count # 辅助函数用于检测单条记录的真实性 def is_consistent(rank, kills): # 这里的实现取决于具体的规则定义 threshold_kills_for_top_5 = {1: 100, 2: 90, 3: 80, 4: 70, 5: 60} if rank <= 5 and kills >= threshold_kills_for_top_5.get(rank, 0): return True elif rank > 5 and kills < sum(threshold_kills_for_top_5.values()) / len(threshold_kills_for_top_5): return True else: return False # 示例调用 n = 15 data = [ (0, 1), (0, 2), (0, 3), (0, 1), (0, 1), (0, 2), (0, 3), (1, 3), (1, 3), (1, 3), (1, 3), (1, 2), (1, 1), (1, 1), (1, 1) ] print(min_lies(n, data)) # 输出结果应匹配预期答案 ``` 上述代码片段展示了如何利用简单的循环与自定义校验函数完成核心功能[^3]。 --- #### 关键点说明 1. **真实性和虚假性的判定标准** - 如果某人声称未参与比赛但实际上排名靠前或者杀敌数目异常高,则视为说谎。 - 反之亦然——即那些说自己很活跃却表现平庸者同样计入统计范围之内。 2. **复杂度考量** 时间复杂度主要由外部迭代次数决定,在本例中大约为 O(N),因为每次仅需评估单一实体的状态即可得出结论。 3. **边界情形测试** 特殊情况下需要注意零值处理、极端高低分差等情况下的行为模式是否合理。 --- ### 结论 综上所述,解决此类问题的关键在于清晰界定何谓“诚实”的填报行为,并据此构建高效的自动化核查机制以减少人为干预带来的误差风险。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值