
浙大PAT
AI记忆
这个作者很懒,什么都没留下…
展开
-
1010. Radix (25)
这道题目我比较清晰的记得参考了wzb56的代码故直接附上wzb56的完整代码,链接:http://blog.youkuaiyun.com/wzb56/article/details/7330762#include #include #define max 11char a[4][max];long long num2Dec(char * p, long long radi转载 2013-03-14 11:55:26 · 3861 阅读 · 3 评论 -
1008. Elevator (20)
考察以时间cost为核心的电梯时间模拟#includeint main(){ int n; while(scanf("%d",&n) != EOF) { int floorNow = 0; int sum = 0; while(n--) { int request; scanf("%d",&request); if(request > floorN原创 2013-03-11 09:07:41 · 2307 阅读 · 0 评论 -
1007. Maximum Subsequence Sum (25)
最大连续子序列和#include#includeint k;typedef struct Node{ int num; int start; int sum;}Node;std::vector d;int main(){ while(scanf("%d",&k)!=EOF) { d.resize(k); for(int i = 0; i < k; ++i)原创 2013-03-11 09:07:28 · 3099 阅读 · 0 评论 -
1005. Spell It Right (20)
考察字符串模拟数字,以及查询表#include#include#includechar g_WordTable[10][100] = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};void OutputWordTable(){ int cnt =原创 2013-03-11 09:06:57 · 2807 阅读 · 0 评论 -
1004. Counting Leaves (30)
考察树结构的简单存储以及遍历搜索#include #include #include int n, m;std::vector> edge;std::vector BFS(int s){ std::queue> q; q.push(std::make_pair(s, 0)); int cur_step = 0; std::vector ans; int cnt = 0;原创 2013-03-11 09:06:31 · 4328 阅读 · 5 评论 -
1043. Is It a Binary Search Tree (25)
考察建立二叉树,以及树的遍历#include#include#includetypedef struct Node{ int key; Node* left; Node* right; Node(Node* _l = NULL, Node* _r = NULL, int _k = -1) :left(_l), right(_r),key(_k){};}Node;vo原创 2013-03-10 21:12:03 · 2711 阅读 · 4 评论 -
1024. Palindromic Number (25)
考察数字字符串操作#include#include#include#include#include#include#include#includeusing namespace std;string Reverse(string a){ string ans; for(int i = 0; i < a.size(); ++i) ans.insert(ans.beg原创 2013-03-10 20:42:37 · 2539 阅读 · 0 评论 -
1023. Have Fun with Numbers (20)
考察数字字符串操作#include#include#include#include#include#include#include#includeusing namespace std;void GetCntTable(string a, vector& cntTable){ cntTable.assign(10, 0); for(int i = 0; i < a.s原创 2013-03-10 20:41:30 · 2980 阅读 · 0 评论 -
1012. The Best Rank (25)
考察结构体排序#include#include#include#include#include#include#include#includeusing namespace std;int n;//studentint m;//querytypedef struct Node{ string name; int grade[4]; int bestRank; i原创 2013-03-10 20:37:26 · 4617 阅读 · 12 评论 -
1051. Pop Sequence (25)
考察数据结构Stack的push跟pop操作 题目链接:http://pat.zju.edu.cn/contests/pat-a-practise/1051#include#include #include #include #include #include #include #include #include using namespace std;int mai原创 2013-03-10 20:22:59 · 3298 阅读 · 0 评论 -
1028. List Sorting (25)
考察结构体排序#include#include#include#includetypedef struct Student{ int id; char name[20]; int g;}Student;int C;bool cmp(Student a, Student b){ if(C == 1) return a.id < b.id; else if(C原创 2013-03-11 09:10:30 · 1990 阅读 · 1 评论 -
1015. Reversible Primes (20)
考察素数以及非10进制到10进制数的转化#include#include#includeint ReverseNumber(int N, int D){ int sum = 0; do { sum = sum*D + N%D; N /= D; }while(N != 0); return sum;}bool IsPrime(int n){ //specia原创 2013-03-11 09:08:24 · 3926 阅读 · 0 评论 -
1029. Median (25)
考察合并序列的中位数#include#includeint main(){ int n1, n2; while(scanf("%d",&n1)!=EOF) { std::vector a, b; for(int i = 0; i < n1; ++i) { int tmp; scanf("%d",&tmp); a.push_back(tmp); }原创 2013-03-11 09:10:34 · 2407 阅读 · 0 评论 -
1031. Hello World for U (20)
考察输出模拟,找输出形式的规律#include#includeint main(){ char str[100]; while(scanf("%s", str) != EOF) { int n = strlen(str); int n1, n2; //find max n1, eg. min n2 for(n2 = 3; n2 <= n; ++n2) {原创 2013-03-12 10:14:23 · 3057 阅读 · 9 评论 -
1035. Password (20)
考察对应字符转化以及信息记录#include#include#includetypedef struct user{ char name[20]; char password[20]; bool modified;}User;bool IsModified(User& a){ int len = strlen(a.password); bool ret = fals原创 2013-03-12 10:15:14 · 2339 阅读 · 0 评论 -
1049. Counting Ones (30)
经典的一道数1的面试题,详细推论以及证明在其他很多博客上都有,讲的都很好看了下所有的PAT考试,里面涉及到的算法和数据结构还是比较集中的。因为PAT测试面向企业,所以还是比较喜欢出经典面试题,而在面试中要考察综合性的编程能力的话,链表和树相关操作都是常考的。#include int Count(int n){ int ans = 0; int base = 1;原创 2013-03-14 11:44:32 · 3050 阅读 · 0 评论 -
PAT解题报告索引
1001. A+B Format (20)http://blog.youkuaiyun.com/sunbaigui/article/details/86569881002. A+B for Polynomials (25)http://blog.youkuaiyun.com/sunbaigui/article/details/86569931003. Emergency (25)http://blog原创 2013-03-13 12:20:58 · 5108 阅读 · 0 评论 -
1039. Course List for Student (25)
倒排索引题这道题目好像是为数不多的一道卡时题,你在PAT刷的很happy的时候,还是要注意下string的滥用的。因为string的拷贝以及比较操作都要比char数组相同操作的效率低。另外其实vector的频繁改变数组大小其实也比较耗时,不过在PAT上还是都可以用vector的。#include#include#include#include#include#incl原创 2013-03-14 11:36:13 · 3139 阅读 · 0 评论 -
1038. Recover the Smallest Number (30)
经典面试题以下关于该解法正确性的详细证明转自何海涛的博客: #include#include#include#includeusing namespace std;bool cmp(string a, string b){ return a+b < b+a;}int main(){ int n; while(scanf("%d",&n)!=EOF) {原创 2013-03-12 10:15:48 · 2517 阅读 · 1 评论 -
1037. Magic Coupon (25)
两数组之间操作事件的模拟#include#includestruct myComp{ bool operator()(const int& a, const int& b) { return a > b; }};int main(){ int nc, np; while(scanf("%d",&nc)!=EOF) { std::multisetc1, p1;原创 2013-03-12 10:15:34 · 1882 阅读 · 0 评论 -
1036. Boys vs Girls (25)
以分数为核心的事件模拟#include#includetypedef struct Student{ char name[20]; char gender; char id[20]; int g;}Student;bool ValidGrade(int g){ if(g >= 0 && g <= 100) return true; else return fal原创 2013-03-12 10:15:24 · 1619 阅读 · 0 评论 -
1011. World Cup Betting (20)
考察查询表以及信息记录#include char g_CharTable[3] = {'W', 'T', 'L'};void CheckCharTable(){ int cnt = 3; for(int i = 0; i < cnt; ++i) printf("%c\n", g_CharTable[i]);}int main(){ //CheckCharTable();原创 2013-03-12 10:16:07 · 2439 阅读 · 1 评论 -
1046. Shortest Distance (20)
考察环模拟操作#include#define MAX 100000int g_Dis[MAX];int g_Sum[MAX+1];int Min(int a, int b){ if(a < b) return a; else return b;}int main(){ int n; while( scanf("%d", &n) != EOF ) { int原创 2013-03-12 10:15:58 · 2041 阅读 · 1 评论 -
1033. To Fill or Not to Fill (25)
加油事件的贪心选择模拟#include#include#includetypedef struct Station{ double dis; double price; bool operator<(const Station& other) const { return dis < other.dis; }}Station;double unit_gas;in原创 2013-03-12 10:14:53 · 3477 阅读 · 6 评论 -
1034. Head of a Gang (30)
考察并查集,以及每个集合的信息记录#include #include #include #include #include #include using namespace std;typedef struct Node{ int weight, parent;}Node;typedef struct Call{ string a, b; int t;}Call原创 2013-03-12 10:15:04 · 4114 阅读 · 0 评论 -
1032. Sharing (25)
考察链表以及相同子链表的搜索记录#include#include#include#includetypedef struct Node{ int adress; Node* next; Node(int _a = 0, Node* _next = NULL):adress(_a),next(_next){};}Node, *PNode;void ReleaseList(原创 2013-03-12 10:14:36 · 1963 阅读 · 0 评论 -
1006. Sign In and Sign Out (25)
考察以时间为核心的事件模拟#includetypedef struct person{ char name[20]; int in; int out;}Person;int main(){ int m; while( scanf("%d", &m) != EOF ) { Person p_in, p_out, tmp; int h1, h2, m1, m2,原创 2013-03-11 09:07:11 · 2621 阅读 · 1 评论 -
1003. Emergency (25)
考察最短路,以及相同最短路存在时的额外信息最优选择#include#include#define INF 0x6FFFFFFFtypedef struct Node{ int nPath; int call; int dis;}Node;std::vector city;std::vector> map;std::vector visit;std::vector t原创 2013-03-11 09:06:12 · 4160 阅读 · 0 评论 -
1026. Table Tennis (30)
考察模拟队列等待这道题目的vip用户以及vip桌子的存在,使得要考虑的case数多了一些另外这个题目的playtime是有截断的#include#include#include#include#include#include#include#includeusing namespace std;typedef struct Node{ int arrive, p原创 2013-03-10 20:46:30 · 3635 阅读 · 0 评论 -
1014. Waiting in Line (30)
考察排队#include#include#include#include#include#include#include#includeusing namespace std;int N;// (<=20, number of windows)int M;// (<=10, the maximum capacity of each line inside the yell原创 2013-03-10 20:40:13 · 3578 阅读 · 0 评论 -
1052. Linked List Sorting (25)
考察链表的知识,以及排序题目链接:http://pat.zju.edu.cn/contests/pat-a-practise/1052#include#include #include #include #include #include #include #include #include using namespace std;typedef struct Nod原创 2013-03-10 20:24:46 · 3306 阅读 · 4 评论 -
1030. Travel Plan (30)
考察最短路及其路径记录#include #include #include #include using namespace std;#define INF 0x6FFFFFFFtypedef struct Node{ int dis, cost, path; Node(){dis=INF; cost=INF; path=-1;}}Node;typedef struct原创 2013-03-11 09:10:43 · 2729 阅读 · 0 评论 -
1018. Public Bike Management (30)
考察最短路,以及记录相同长度最短路,然后遍历选择最优最短路#include#include#include#includeusing namespace std;#define INF 0x6FFFFFFFint Cmax, n, Sp, m;typedef struct Edge{ int v, dis; Edge(int _v, int _dis):v(_v),dis原创 2013-03-11 09:09:30 · 4797 阅读 · 0 评论 -
1017. Queueing at Bank (25)
参考自:考察排队事件的模拟#include#include#includeusing namespace std;struct window{ int mm; int hh; int ss; bool operator<(const window& a)const { if(hh>a.hh) return tru原创 2013-03-11 09:09:21 · 3768 阅读 · 1 评论 -
1016. Phone Bills (25)
参考自:考察以时间为核心的电话账单事件模拟以及统计#includeusing namespace std;#include#include#includestruct Call{ string name; int month; int date; int hour; int minute; int total; string status;};int原创 2013-03-11 09:08:35 · 3627 阅读 · 0 评论 -
1001. A+B Format (20)
字符串模拟数字操作#include#include//using namespace std;int main(){ int a, b; while(scanf("%d%d",&a,&b)!=EOF) { int ans = a+b; int flag = 1;//1 nonnegtive; 0 negtive if(ans < 0) flag = 0, ans =原创 2013-03-10 21:22:07 · 3813 阅读 · 0 评论 -
1048. Find Coins (25)
考察查询表#include#include#define FaceMax 1000int main(){ int n, m; while(scanf("%d%d",&n,&m)!=EOF) { //input std::vector coins; coins.assign(FaceMax+1, 0); while(n--) { int tmp;原创 2013-03-10 21:18:50 · 2217 阅读 · 0 评论 -
1025. PAT Ranking (25)
考察结构体排序以及合并操作#include#include#include#include#include#include#include#includeusing namespace std;typedef struct Node{ string registrition_number; int grade; int location_number; int l原创 2013-03-10 20:44:06 · 2441 阅读 · 0 评论 -
1053. Path of Equal Weight (30)
考察链表,排序,以及深度搜索题目链接:http://pat.zju.edu.cn/contests/pat-a-practise/1053#include#include #include #include #include #include #include #include #include using namespace std;int N, M, T;typ原创 2013-03-10 20:26:28 · 2753 阅读 · 1 评论 -
1041. Be Unique (20)
考察查询表#include#includetypedef struct lottery{ int cnt; int index; lottery(int _cnt = 0, int _index = 0):cnt(_cnt),index(_index){}}Lottery;#define MAX 10000int main(){ int N; while( scanf原创 2013-03-10 21:08:42 · 1773 阅读 · 0 评论