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