题解:CF2051C Preparing for the Exam

CF2051C Preparing for the Exam

思路

其实莫非就三种情况:

  • 所有题目都会:所有试卷也都会。
  • \(\ge 2\) 道题目不会:所有试卷都不会。
  • \(1\) 道题目不会:假设这道题目是 \(x\),那么遍历数组 \(q\) 寻找是否有 \(q_i=x\),如果有则输出 \(1\),否者输出 \(0\)

AC 代码

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

#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 记录

posted @ 2024-12-27 11:33  SuperJimmy  阅读(33)  评论(0)    收藏  举报