转换进制&&逆序可以在一起进行,有一点技巧,不要用十进制数来表示低进制,容易溢出. #include <iostream> #include <vector> using namespace std; bool isPrime(int n) { if(n < 2) return false; if(n == 2) return true; if(n % 2 == 0) return false; for(int i = 3; i < n; i += 2)…
PAT (Advanced Level) Practice 1015 Reversible Primes (20 分) 凌宸1642 题目描述: A reversible prime in any number system is a prime whose "reverse" in that number system is also a prime. For example in the decimal system 73 is a reversible prime because…
A reversible prime in any number system is a prime whose "reverse" in that number system is also a prime. For example in the decimal system 73 is a reversible prime because its reverse 37 is also a prime. Now given any two positive integers N (&…
题意: 每次输入两个正整数N,D直到N是负数停止输入(N<1e5,1<D<=10),如果N是一个素数并且将N转化为D进制后逆转再转化为十进制后依然是个素数的话输出Yes,否则输出No. trick: 判断转化后的数是不是1,1不是素数,如果转化后不是1说明转化前也不会是1(第一个测试点错误原因). AAAAAccepted code: #include<bits/stdc++.h> using namespace std; int main(){ int n,d; while…
没什么难的,简单模拟题 #include <iostream> using namespace std; int main() { int num; cin>>num; int cost = 0; int curFloor = 0; while (num--) { int floor; cin>>floor; int tmp = floor - curFloor; cost += tmp > 0 ? 6 * tmp : -4 * tmp; cost += 5; c…
利用广度优先搜索,找出每层的叶子节点的个数. #include <iostream> #include <vector> #include <queue> #include <fstream> using namespace std; vector<vector<int>> tree; vector<int> ans; void BFS(int s) { queue<pair<int, int>>…
关键在于清空字符数组和使用scanf进行输入 #include <stdio.h> #include <string.h> #include <fstream> #include <iostream> using namespace std; int main() { int num; while (scanf("%d", &num) != EOF) { char earlest[20]; char lastest[20]; ch…
简单模拟题,注意读懂题意就行 #include <iostream> #include <queue> using namespace std; #define CUSTOMER_MAX 1000+1 #define INF 0x6fffffff #ifndef LOCAL // #define LOCAL #endif LOCAL int n; // number of windows <=20 int m ;// queue capacity <=10 int k;…
简单模拟题,遍历一遍即可.考察输入输出. #include <iostream> #include <string> #include <stdio.h> #include <iomanip> using namespace std; #define N 3 int main() { char res[3]={'W','T','L'}; char max_res[N]; int i,j; float tmp,sum=1,odd; for(i=0;i<N…
这题给定了一个图,我用DFS的思想,来求出在图中去掉某个点后还剩几个相互独立的区域(连通子图). 在DFS中,每遇到一个未访问的点,则对他进行深搜,把它能访问到的所有点标记为已访问.一共进行了多少次这样的搜索, 就是我们要求的独立区域的个数. #include <iostream> #include <fstream> #include <memory.h> using namespace std; const int maxNum = 1001; bool visit…