PAT - 甲级 - 1116. Come on! Let's C (20) (桶排思想)
来源:互联网 发布:非农数据公布日期 编辑:程序博客网 时间:2024/06/06 07:22
"Let's C" is a popular and fun programming contest hosted by the College of Computer Science and Technology, Zhejiang University. Since the idea of the contest is for fun, the award rules are funny as the following:
0. The Champion will receive a "Mystery Award" (such as a BIG collection of students' research papers...).
1. Those who ranked as a prime number will receive the best award -- the Minions (小黄人)!
2. Everyone else will receive chocolates.
Given the final ranklist and a sequence of contestant ID's, you are supposed to tell the corresponding awards.
Input Specification:
Each input file contains one test case. For each case, the first line gives a positive integer N (<=10000), the total number of contestants. Then N lines of the ranklist follow, each in order gives a contestant's ID (a 4-digit number). After the ranklist, there is a positive integer K followed by K query ID's.
Output Specification:
For each query, print in a line "ID: award" where the award is "Mystery Award", or "Minion", or "Chocolate". If the ID is not in the ranklist, print "Are you kidding?" instead. If the ID has been checked before, print "ID: Checked".
Sample Input:61111666688881234555500016888800011111222288882222Sample Output:
8888: Minion0001: Chocolate1111: Mystery Award2222: Are you kidding?8888: Checked2222: Are you kidding?
题目大意:给出n个人的排名。
1.第一名的奖品:Mystery Award(神秘大奖)
2.排名是素数的奖品:Minions (小黄人)
3.其他人的奖品:chocolates(巧克力)
给出要查询的n个人的号码,查询获奖信息
1.该人信息存在并且第一次查询:输出获奖信息
2.该人信息存在但非第一次查询:Checked
3.该人信息不存在:输出Are you kidding?
注意输出的格式。
思路,用桶排的思想,所谓一个萝卜一个坑,
初始化这个坑是0代表不存在该人信息
1代表第一名,
2代表排名为素数,
3代表除1,2的其他人,
-1代表查询过。
#include<cstdio>#include<cmath>#include<cstring>#define N 10000using namespace std;int a[N],n,b;//判断素数 bool is_p(int a){if(a==1)return false;for(int i=2 ;i<=sqrt(a) ;i++){if(a%i==0)return false;}return true;}int main(){scanf("%d",&n);memset(a,0,sizeof(a));//信息输入 for(int i=1 ;i<=n ;i++){scanf("%d",&b);if(i==1) a[b] = 1;else if(is_p(i)) a[b] = 2;else a[b] = 3;}//查询操作 scanf("%d",&n);for(int i=0 ;i<n ;i++){scanf("%d",&b);if(a[b]==1){printf("%04d: Mystery Award\n",b);a[b]=-1;continue;}if(a[b]==2){printf("%04d: Minion\n",b);a[b]=-1;continue;}if(a[b]==3){printf("%04d: Chocolate\n",b);a[b]=-1;continue;}if(a[b]==0){printf("%04d: Are you kidding?\n",b);continue;}if(a[b]==-1){printf("%04d: Checked\n",b);a[b]=-1;continue;}}return 0;}
- PAT - 甲级 - 1116. Come on! Let's C (20) (桶排思想)
- PAT 甲级 1116. Come on! Let's C (20)
- 1059. C语言竞赛(20) PAT 乙级&&1116. Come on! Let's C (20) PAT甲级
- 1116. Come on! Let’s C (20)-PAT甲级真题
- PAT--1116. Come on! Let's C
- PAT 1116. Come on! Let's C
- 【PAT】1116. Come on! Let's C
- pat 1116. Come on! Let's C
- PAT(A) 1116. Come on! Let's C (20)
- 【PAT】【Advanced Level】1116. Come on! Let's C (20)
- 1116. Come on! Let's C (20)
- 1116. Come on! Let's C (20)
- 1116. Come on! Let's C (20)
- 1116. Come on! Let's C (20)
- 1116. Come on! Let's C (20)
- 1116. Come on! Let's C (20)
- 1116. Come on! Let's C (20)
- 1116. Come on! Let's C (20)
- 区块链:去中心化的交易所方向
- MacOS X下开启root用户
- push时隐藏tabbar
- 退出App的几种方法
- 分布式与集群的联系与区别
- PAT - 甲级 - 1116. Come on! Let's C (20) (桶排思想)
- java基础巩固----jdbc接口PreparedStatement vs Statment
- 代码量统计
- Spring Boot Shiro 权限信息缓存处理,记住我,thymleaf使用shiro标签
- 如何查看自己的某个应用程序被某个端口占用问题
- 浅谈RecyclerView(一)
- PE文件操作类
- POJ1664 记忆递归
- 感知机的java实现