1168 Prime Day

The above picture is from Sina Weibo, showing May 23rd, 2019 as a very cool “Prime Day”. That is, not only that the corresponding number of the date 20190523 is a prime, but all its sub-strings ended at the last digit 3 are prime numbers.

Now your job is to tell if a given date is a Prime Day.

Input Specification:

Each input file contains one test case. For each case, a date between January 1st, 0001 and December 31st, 9999 is given, in the format yyyymmdd.

Output Specification:

For each given date, output in the decreasing order of the length of the substrings, each occupies a line. In each line, print the string first, followed by a space, then Yes if it is a prime number, or No if not. If this date is a Prime Day, print in the last line All Prime!.

Sample Input 1:

20190523

Sample Output 1:

20190523 Yes
0190523 Yes
190523 Yes
90523 Yes
0523 Yes
523 Yes
23 Yes
3 Yes
All Prime!
Sample Input 2:
20191231
Sample Output 2:
20191231 Yes
0191231 Yes
191231 Yes
91231 No
1231 Yes
231 No
31 Yes
1 No
#include<bits/stdc++.h>
using namespace std;
bool isprime(int n){if(n<=1) return false;int sqr=sqrt(n*1.0);for(int i=2;i<=sqr;i++){if(n%i==0) return false;}return true;
}
int main(){string s;cin>>s;int flag=1;while(s.length()>0){int t=stoi(s);cout<<s<<" ";if(isprime(t)) printf("Yes\n");else {flag=0;printf("No\n");}s.erase(s.begin());}if(flag) printf("All Prime!");return 0;
}

1169 The Judger

A game of numbers has the following rules: at the beginning, two distinct positive integers are given by the judge. Then each player in turn must give a number to the judge. The number must be the difference of two numbers that are previously given, and must not be duplicated to any of the existed numbers. The game will run for several rounds. The one who gives a duplicate number or even a wrong number will be kicked out.

Your job is to write a judger program to judge the players’ numbers and to determine the final winners.

Input Specification:

Each input file contains one test case. For each case, the first line gives two distinct positive integers to begin with. Both numbers are in [1,10^5 ].

In the second line, two numbers are given: N (2≤N≤10), the number of players, and M (2≤M≤10^3), the number of rounds.

Then N lines follow, each contains M positive integers. The i-th line corresponds to the i-th player (i=1,⋯,N). The game is to start from the 1st player giving his/her 1st number, followed by everybody else giving their 1st numbers in the 1st round; then everyone give their 2nd numbers in the 2nd round, and so on so forth.

Output Specification:

If the i-th player is kicked out in the k-th round, print in a line Round #k: i is out… The rest of the numbers given by the one who is out of the game will be ignored. If more than one player is out in the same round, print them in increasing order of their indices. When the game is over, print in the last line Winner(s): W1 W2 … Wn, where W1 … Wn are the indices of the winners in increasing order. All the numbers in a line must be separated by exactly one space, and there must be no extra space at the beginning or the end of the line. If there is no winner, print No winner. instead.

Sample Input 1:

101 42
4 5
59 34 67 9 7
17 9 8 50 7
25 92 43 26 37
76 51 1 41 40

Sample Output 1:

Round #4: 1 is out.
Round #5: 3 is out.
Winner(s): 2 4

Sample Input 2:

42 101
4 5
59 34 67 9 7
17 9 18 50 49
25 92 58 1 39
102 32 2 6 41

Sample Output 2:

Round #1: 4 is out.
Round #3: 2 is out.
Round #4: 1 is out.
Round #5: 3 is out.
No winner.
#include<bits/stdc++.h>
using namespace std;
int main() {int n1,n2,n,m,isout[12]= {0},v[12][1005]= {0},exist[200010]= {0};vector<int> win,ex;scanf("%d%d%d%d",&n1,&n2,&n,&m);for(int i=1; i<=n; i++) {for(int j=1; j<=m; j++) {scanf("%d",&v[i][j]);}}ex.push_back(n1);ex.push_back(n2);exist[n1]=1;exist[n2]=1;for(int j=1; j<=m; j++) {for(int i=1; i<=n; i++) {int flag=0;if(isout[i]==1) continue;if(exist[v[i][j]]==1) {isout[i]=1;printf("Round #%d: %d is out.\n",j,i);continue;}for(int k=0; k<ex.size(); k++) {if(exist[v[i][j]+ex[k]]==1) {flag=1;break;}}if(flag==0) {isout[i]=1;printf("Round #%d: %d is out.\n",j,i);continue;}exist[v[i][j]]=1;ex.push_back(v[i][j]);}}for(int i=1;i<=n;i++){if(isout[i]==0) win.push_back(i);}if(win.size()==0) printf("No winner.\n");else{printf("Winner(s):");for(int i=0;i<win.size();i++) printf(" %d",win[i]);}return 0;
}

1170 Safari Park

A safari park(野生动物园)has K species of animals, and is divided into N regions. The managers hope to spread the animals to all the regions, but not the same animals in the two neighboring regions. Of course, they also realize that this is an NP complete problem, you are not expected to solve it. Instead, they have designed several distribution plans. Your job is to write a program to help them tell if a plan is feasible.

Input Specification:

Each input file contains one test case. For each case, the first line gives 3 integers: N (0<N≤500), the number of regions; R (≥0), the number of neighboring relations, and K (0<K≤N), the number of species of animals. The regions and the species are both indexed from 1 to N.

Then R lines follow, each gives the indices of a pair of neighboring regions, separated by a space.

Finally there is a positive M (≤20) followed by M lines of distribution plans. Each plan gives N indices of species in a line (the i-th index is the animal in the i-th rigion), separated by spaces. It is guaranteed that any pair of neighboring regions must be different, and there is no duplicated neighboring relations.

Output Specification:

For each plan, print in a line Yes if no animals in the two neighboring regions are the same, or No otherwise. However, if the number of species given in a plan is not K, you must print Error: Too many species. or Error: Too few species. according to the case.

Sample Input:

6 8 3
2 1
1 3
4 6
2 5
2 4
5 4
5 6
3 6
5
1 2 3 3 1 2
1 2 3 4 5 6
4 5 6 6 4 5
2 3 4 2 3 4
2 2 2 2 2 2

Sample Output:

Yes
Error: Too many species.
Yes
No
Error: Too few species.
#include<bits/stdc++.h>
using namespace std;
int main() {int n,r,k,m;scanf("%d%d%d",&n,&r,&k);vector<int> v[r];for(int i=0; i<r; i++) {int v1,v2;scanf("%d%d",&v1,&v2);v[i].push_back(v1);v[i].push_back(v2);}scanf("%d",&m);for(int i=0; i<m; i++) {int g[510],flag=1;set<int>s;for(int j=1; j<=n; j++) {scanf("%d",&g[j]);s.insert(g[j]);}if(s.size()>k) {printf("Error: Too many species.\n");continue;} else if(s.size()<k) {printf("Error: Too few species.\n");continue;}for(int j=0; j<r; j++) {if(g[v[j][0]]==g[v[j][1]]) {flag=0;printf("No\n");break;}}if(flag==1) printf("Yes\n");}return 0;
}

1171 Replacement Selection

When the input is much too large to fit into memory, we have to do external sorting instead of internal sorting. One of the key steps in external sorting is to generate sets of sorted records (also called runs) with limited internal memory. The simplest method is to read as many records as possible into the memory, and sort them internally, then write the resulting run back to some tape. The size of each run is the same as the capacity of the internal memory.

Replacement Selection sorting algorithm was described in 1965 by Donald Knuth. Notice that as soon as the first record is written to an output tape, the memory it used becomes available for another record. Assume that we are sorting in ascending order, if the next record is not smaller than the record we have just output, then it can be included in the run.

For example, suppose that we have a set of input { 81, 94, 11, 96, 12, 99, 35 }, and our memory can sort 3 records only. By the simplest method we will obtain three runs: { 11, 81, 94 }, { 12, 96, 99 } and { 35 }. According to the replacement selection algorithm, we would read and sort the first 3 records { 81, 94, 11 } and output 11 as the smallest one. Then one space is available so 96 is read in and will join the first run since it is larger than 11. Now we have { 81, 94, 96 }. After 81 is out, 12 comes in but it must belong to the next run since it is smaller than 81. Hence we have { 94, 96, 12 } where 12 will stay since it belongs to the next run. When 94 is out and 99 is in, since 99 is larger than 94, it must belong to the first run. Eventually we will obtain two runs: the first one contains { 11, 81, 94, 96, 99 } and the second one contains { 12, 35 }.

Your job is to implement this replacement selection algorithm.

Input Specification:

Each input file contains several test cases. The first line gives two positive integers N (≤105) and M (<N/2), which are the total number of records to be sorted, and the capacity of the internal memory. Then N numbers are given in the next line, all in the range of int. All the numbers in a line are separated by a space.

Output Specification:

For each test case, print in each line a run (in ascending order) generated by the replacement selection algorithm. All the numbers in a line must be separated by exactly 1 space, and there must be no extra space at the beginning or the end of the line.

Sample Input:

13 3
81 94 11 96 12 99 17 35 28 58 41 75 15

Sample Output:

11 81 94 96 99
12 17 28 35 41 58 75
15
#include<bits/stdc++.h>
using namespace std;
int main() {int n,m;scanf("%d%d",&n,&m);vector<int> v;for(int i=0; i<n; i++) {int temp;scanf("%d",&temp);v.push_back(temp);}priority_queue<int,vector<int>,greater<int> > q;int index=0,count=0,TOP;vector<int>temp,ans;while(index<m) q.push(v[index++]);while(count!=n) {TOP=q.top();ans.push_back(TOP);q.pop();count++;if(index<n) {if(v[index]>TOP) q.push(v[index++]);else temp.push_back(v[index++]);}if(q.empty()) {for(int i=0; i<ans.size(); i++) {if(i>0) printf(" ");printf("%d",ans[i]);}printf("\n");ans.clear();for (int i = 0; i < temp.size(); i++)//v的数全都放到q里q.push(temp[i]);temp.clear();}}return 0;
}

2020年PAT甲级春季考试真题及答案相关推荐

  1. 中学教师资格考试真题及答案

    为大家整理了中学教师考试真题及答案,我们先来了解下教师资格笔试考试科目. 教师资格笔试考试科目 幼儿园教资笔试科目为<综合素质>(幼儿园).<保教知识与能力>:小学教资笔试科目 ...

  2. PAT甲级(Advanced Level)真题--1046 Sharing

    PAT甲级(Advanced Level)真题–1046 Sharing 通过:648 提交:1138 通过率:56% To store English words, one method is to ...

  3. PAT甲级(Advanced Level)真题-- 1062 To Buy or Not to Buy

    PAT甲级(Advanced Level)真题-- 1062 To Buy or Not to Buy 通过:643 提交:1220 通过率:52% Eva would like to make a ...

  4. 2009年出现的计算机术语,2009年计算机一级考试真题及答案

    2009年计算机一级考试真题及答案 一.选择题 1.在计算机领域中通常用MIPS来描述______. A.计算机的运算速度 B.计算机的可靠性 C.计算机的可运行性 D.计算机的可扩充性 2.微型计算 ...

  5. 2011年9月计算机C语言真题,2011年9月全国计算机二级C语言考试真题及答案.doc

    2011年9月全国计算机二级C语言考试真题及答案 2011年9月全国计算机等级考试二级笔试试卷 ?C语言程序设计 ?(考试时间90分钟,满分100分) 一.选择题((1)-(10).(21)-(40) ...

  6. 英语阅读计算机病毒是指,2016年职称计算机考试真题及答案

    2016年职称计算机考试真题及答案 31.计算机的软件一般包括( D ) A实阴德软件和应用软件 B.系统软件和管理软件 C.培训软件和源程序 D.系统软件和应用软件 32.下面( C )是系统软件. ...

  7. 目前微型计算机中常用的鼠标器有什么两类,2009年计算机一级考试真题及答案...

    2009年计算机一级考试真题及答案. 一.选择题 1.在计算机领域中通常用M IPS来描述______. A.计算机的运算速度 B.计算机的可靠性 C.计算机的可运行性 D.计算机的可扩充性 2.微型 ...

  8. 高中计算机教师招聘试题,中小学信息技术教师招聘考试真题及答案.doc

    中小学信息技术教师招聘考试真题及答案 一.选择题(60个) 1.网页都是按照一种描述文档的标记规则编写而成的,这套标记规则叫做:C A.URLB.HTTPC.HTMLD.FTP 2.Basic语言属于 ...

  9. 2020年系统集成项目管理工程师上午真题及答案解析

    2020年系统集成项目管理工程师上午真题及答案解析 1.信息系统的()是指系统可能存在着丧失结构.功能.秩序的特性. A可用性 B.开放性 C脆弱性 D.稳定性 [参考答案] C 2.()可以将计算机 ...

最新文章

  1. 使用Flink的Savepoint功能
  2. FirewallD 详解
  3. vs2010 Qt插件报错Couldn't register all Qt4VSAddin command解决方案
  4. Oldboy28期linux决心书
  5. Springboot配置不当
  6. MVC视图之间调用方法总结
  7. Linux自动化安装cobbler
  8. exit(0)和exit(1)区别
  9. 26秒!全球销量第一的AI音箱就被腾讯黑掉了,然后变身窃听器
  10. 关于WEB集群中文件服务器的讨论
  11. Struts2基本的执行过程
  12. fences卸载_图文帮您win10系统卸载fences的设置技巧
  13. 〖Python 数据库开发实战 - MySQL篇②〗- 一文通解关系型数据库与非关系型数据库
  14. 首批企业入驻“一县一店”:多元化方式助力农产外销
  15. android5去wifi感叹号,android 5.1 WIFI图标上的感叹号及其解决办法
  16. 深度学习基础知识点归纳总结
  17. 联想集团:2021/22财年第一季度业绩
  18. uniapp h5 海报
  19. 使用 mv 命令移动文件夹
  20. python 拼音库_python有没有拼音库python进阶之socket详解

热门文章

  1. 通过CMM5/CMMI5级的企业
  2. 沃通免费ssl服务器证书,新版《沃通免费SSL证书申请指南》
  3. HTML链接(详细)与分割线(部分)
  4. mac qq 聊天记录 图片缓存 存放位置
  5. 淘宝分词怎么查看,详谈淘宝分词原则
  6. STC8H开发(六): SPI驱动ADXL345三轴加速度检测模块
  7. 大城市核心区步行和自行车系统规划策略
  8. 傅里叶变换:空间域与频率域,dft输出的实部与虚部
  9. mysql快捷键前进_mysql快捷键
  10. 电脑强制关机后mysql_电脑强制关机后变得干什么都特别卡!求解?