1059 C语言竞赛 (20 分)
题目链接
算法分析
跑一边素数筛(欧拉筛),用map结构记录每位选手的排名,然后进行查询和特判。
代码实现
#include<bits/stdc++.h>
using namespace std;
#define N 10005
map< int, int >rak;
int is[N];
int on[N], prime[N], t;
void init(){
on[0] = on[1] = 1;
for(int i = 2; i < 10000; ++ i){
if(!on[i]) prime[++ t] = i;
for(int j = 1; j <= t && i * prime[j] <= 10000; ++ j){
on[i * prime[j]] = 1;
if(i % prime[j] == 0) break;
}
}
return ;
}
int main(){
init();
int n, id, k;
scanf("%d", &n);
for(int i = 1; i <= n; ++ i){
scanf("%d", &id);
rak[id] = i;
}
scanf("%d", &k);
for(int i = 1; i <= k; ++ i){
scanf("%d", &id);
if(!rak[id]){
printf("%04d: Are you kidding?\n", id);
continue;
}
if(is[id]){
printf("%04d: Checked\n", id);
continue;
}
if(rak[id] == 1){
printf("%04d: Mystery Award\n", id);
is[id] = 1;
continue;
}
if(!on[rak[id]]){
printf("%04d: Minion\n", id);
is[id] = 1;
continue;
}
printf("%04d: Chocolate\n", id);
is[id] = 1;
}
return 0;
}