![](https://img-blog.csdnimg.cn/20201014180756738.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
pat
linest00
这个作者很懒,什么都没留下…
展开
-
pat-1001 A+B Format
1001:将两数之和转换成3位一逗号 Sample Input -1000000 9 Sample Output -999,991 [code="c++"] #include using namespace std; #include void format(int num) { if(num>=1000) { format(num/1000); ...2011-09-15 20:44:23 · 50 阅读 · 0 评论 -
pat-1015 Reversible Primes
将数字转成指定进制,再反序,判断原数和新数是否都是质数。 注意质数判断时要有等号,如25的平方根5,注意0和1的特判。 本题中,进制转换和反序可以一次完成。 [code="c++"] #include using namespace std; #include bool isPrime(int n) { if(n==1||n==0) return false;...2011-09-28 20:08:24 · 118 阅读 · 0 评论 -
pat-1023 Have Fun with Numbers
判断一个数乘2后是否是原数的一个排列 思路: int最大值 2147483647 10位 longlong 最大值 9223372036854775807 19位 不满足题目20位 故不能数值型 只能字符串处理 考虑乘积后进位问题 排列的判断用二进制移位求和即可,和值相等即为排列。 [code="c++"] #include using namespa...2012-02-19 00:26:55 · 105 阅读 · 0 评论 -
pat-1025 PAT Ranking
不同地点一起排序 先组内排序,再全局排序 将小组添加进全局 vector拼接 globallist.insert(globallist.end(),locallist.begin(),locallist.end()); [code="c++"] #include using namespace std; #include #include #include ...2012-02-19 15:45:07 · 78 阅读 · 0 评论 -
pat-1024 Palindromic Number
如果不是回文则进行逆序相加操作,打印出最后回文和操作次数 题目中说数字可达到10的10次方 迭代可100次 则每次相加次数可能因进位多一位,longlong型只能19位可能不够 实现重点,字符串相加 注意求进位时也要带上carry 以下代码数值型会溢出 [code="c++"] #include using namespace std; long long ...2012-02-20 00:56:42 · 115 阅读 · 0 评论 -
pat-1019 General Palindromic Number
判断数字在给定进制下是否回文 并打出进制转换后系数 思路,将所有系数存起来处理 [code="c++"] #include using namespace std; #include #include int main() { vector v; vector rv; int num; int base; cin>>num; cin>>...原创 2012-02-23 00:26:35 · 74 阅读 · 0 评论 -
pat-1020* Tree Traversals
给后序和中序遍历 求层序遍历 Sample Input:7 2 3 1 5 7 6 4 1 2 3 4 5 6 7 Sample Output:4 1 6 3 5 7 2 注意如果是按char型处理,还要考虑多字符情况 如12 在输入上要加以处理,用int比较简单 [code="c++"] #include "stdio.h" #include "stdlib...2012-02-23 15:20:15 · 97 阅读 · 0 评论 -
pat-1021* Deepest Root
判断图是否都连接构成树,求使树高最大的根 实际上求图上两点间最大距离 先用并查集判断共有几个部分 bfs求距离 先任取一点开始bfs,得到最远的叶节点 以此叶节点再bfs可得 [code="c++"] #include using namespace std; #include #include #include #include #include #i...2012-02-25 00:36:00 · 91 阅读 · 0 评论 -
pat-1017* Queueing at Bank
银行8点至17点开 有固定窗口数 来早了要等,没窗口要等,17点后才来就无视 求平均等待时间, 被无视的不统计 注意不是17点一定关门,只要是17点前来的都要服务,即使可能超时 下面代码完全模拟秒数,先排序顾客,滤掉17点后来的 对于每一秒,检查窗口的情况 总体思路是以时间为中心 [code="c++"] #include using namespace std;...2012-02-25 12:32:43 · 86 阅读 · 0 评论 -
pat-1018 Public Bike Management 有问题
最后一个case还过不了 == 为什么呢 思路dfs遍历到目标的所有路径 找最短,运送最少,带回最少的路径 [code="c++"] #include #include #include using namespace std; #define MAXV 501 #define INFINITE 1000000000 int mindis = INFINITE...2012-02-26 19:55:45 · 96 阅读 · 0 评论 -
pat-1016 Phone Bills
Sample Input:10 10 10 10 10 10 20 20 20 15 15 15 15 15 15 15 20 30 20 15 15 10 10 10 10 CYLL 01:01:06:01 on-line CYLL 01:28:16:05 off-line CYJJ 01:01:07:00 off-line CYLL 01:01:08:03 off-line C...2012-02-27 00:01:11 · 154 阅读 · 0 评论 -
pat-1009 Product of Polynomials
1009:多项式乘积。 Sample Input 2 1 2.4 0 3.2 2 2 1.5 1 0.5 Sample Output 3 3 3.6 2 6.0 1 1.6 用数组保存。如果稀疏的话有点费内存。。。 [code="c++"] #include using namespace std; #include #include double a[1001...2011-09-19 23:31:03 · 51 阅读 · 0 评论 -
pat-1008 Elevator
1008: 电梯上升一层6秒,下降4秒,停留5秒。给出请求序列求总时间。 Sample Input: 3 2 3 1 Sample Output: 41 [code="c++"] #include using namespace std; int main() { int curr=0; int next; int n; int time=0; ...2011-09-19 23:09:49 · 73 阅读 · 0 评论 -
pat-1007 Maximum Subsequence Sum
1007:连续和最大子串。 O(n)时间即可完成,不需存储空间。 [code="c++"] #include using namespace std; int main() { int n; int max; int sum; bool isfirst=true; int num; int low; int high; int tmp; ...2011-09-19 22:59:33 · 126 阅读 · 0 评论 -
pat-1002 A+B for Polynomials
1002:多项式加法 Sample Input 2 1 2.4 0 3.2 2 2 1.5 1 0.5 Sample Output 3 2 1.5 1 2.9 0 3.2 数组保存。 [code="c++"] #include using namespace std; #include #include double exp[1001]; int ma...2011-09-15 21:15:34 · 47 阅读 · 0 评论 -
pat-1003* Emergency
1003: dfs遍历所有路径。 [code="c++"] #include #include using namespace std; int city; int road; int collect=0; int maxcollect=0; int shortnum=0; int used[501]; int team[501]={0}; int minpa...2011-09-15 23:08:38 · 129 阅读 · 0 评论 -
pat-1011 World Cup Betting
1011: 每行找最大值,相乘即可。 [code="c++"] #include #include using namespace std; int main() { double max; double res=1; double a,b,c; char type; for(int i=0;i>a; cin>>b; cin>>c; ...2011-09-15 23:45:34 · 62 阅读 · 0 评论 -
pat-1013* Battle Over Cities
1013: 删除一个结点后保持其他结点连通性的问题 dfs遍历 看有多少划分 可能效率不是很好 [code="c++"] #include using namespace std; #include int map[1001][1001]; int sto[1001][1001]; int city; int way; int num; void dfs(int...2011-09-16 22:55:00 · 60 阅读 · 0 评论 -
pat-1012 The Best Rank
1012: 找出最佳排名 代码有点冗余。。。用了一些stl容器 有重复时注意排名顺序。 1 2 3 3 5 不是 1 2 3 3 4 。。。。。 [code="c++"] #include #include using namespace std; #include #include #include struct Stu { int id; int...2011-09-16 23:58:39 · 107 阅读 · 0 评论 -
pat-1014* Waiting in Line
1014: 排队服务问题,队列实现。 注意条件控制。 [code="c++"] #include using namespace std; #include #include #include struct People { int id; int cost; bool start; }; queue q[30]; queue wait; map ...2011-09-17 10:42:20 · 90 阅读 · 0 评论 -
pat-1010* Radix
1010: 给出两个数,已知一个数的进制,求是否可以在某进制下两数相等。 如例子一,第一个数为10进制6 110 如果2进制则相等。 Sample Input 1: 6 110 1 10 Sample Output 1: 2 Sample Input 2: 1 ab 1 2 Sample Output 2: Impossible 不用二分搜索时第7case超时 ,用了二...2011-09-17 19:36:44 · 73 阅读 · 0 评论 -
pat-1004* Counting Leaves
1004: 统计树的每一层上叶子节点的个数 Sample Input 2 1 01 1 02 Sample Output 0 1 用二维数组存了树,dfs搜索了一下。最左一列统计节点孩子数量,最上一行用于记录每层叶子数。 [code="c++"] #include using namespace std; #include #include int tree...2011-09-18 22:35:39 · 107 阅读 · 0 评论 -
pat-1005 Spell It Right
1005:计算各个数字的和,并翻译成英文。 Sample Input: 12345 Sample Output: one five 递归实现,注意一下空格分隔的方法 [code="c++"] #include using namespace std; #include char number[120]; void convert(int i) { swi...2011-09-18 22:52:35 · 69 阅读 · 0 评论 -
pat-1006 Sign In and Sign Out
1006:给出进入和离开时间,求最早来和最晚走的人 Sample Input: 3 CS301111 15:30:28 17:00:10 SC3021234 08:00:00 11:25:25 CS301133 21:45:00 21:58:40 Sample Output: SC3021234 CS301133 将时间转化成数字进行比较即可。 c++ 里貌似没有类似...2011-09-18 23:35:49 · 141 阅读 · 0 评论 -
pat-1022 Digital Library
可能的查询 ID值进行map映射 以下代码有问题,原因是ID是整形保存,会忽略前面的0 [code="c++"] #include using namespace std; #include #include #include #include #include int main() { int N; map m; int ID; int...2012-02-27 14:26:56 · 84 阅读 · 0 评论