跳到正文

题解

题解:CF2051C Preparing for the Exam

JimmyQ约 2 分钟
原文
文章信息与版本

文章信息

发布
2024年12月26日
收录
2025年12月12日
更新
2026年11月17日
篇幅
约 2 分钟
获赞
2
题目
CF2051C

版本

  1. v1当前

CF2051C Preparing for the Exam

思路

其实莫非就三种情况:

  • 所有题目都会:所有试卷也都会。
  • 有 ≥2\ge 2 道题目不会:所有试卷都不会。
  • 有 11 道题目不会:假设这道题目是 xx,那么遍历数组 qq 寻找是否有 qi=xq_i=x,如果有则输出 11,否者输出 00。

AC 代码

时间复杂度为Θ(tn)\Theta(tn)。

C++
#include<bits/stdc++.h>
using namespace std;
#define N 300005
long long n,m,k,t,b[N],q[N],vis[N];
int main(){
	cin>>t;
	while(t--){
		cin>>n>>m>>k;
		memset(vis,0,sizeof(vis));
		for(int i=1;i<=m;i++) cin>>b[i];
		for(int i=1;i<=k;i++) cin>>q[i];
		if(k==n){
			for(int i=1;i<=m;i++) cout<<1;
		}
		else if(k==n-1){
			long long now;
			for(int i=1;i<=k;i++) vis[q[i]]=1;
			for(int i=1;i<=n;i++){
				if(vis[i]==0){
					now=i;
					break;
				}
			}
			for(int i=1;i<=m;i++){
				if(b[i]==now) cout<<1;
				else cout<<0; 
			}
		}
		else for(int i=1;i<=m;i++) cout<<0;
		cout<<endl;
	}
	return 0;
} 

AC 记录

原文