
PAT
lambsnow
博文中的解法全部AC过的
展开
-
【PAT甲级】1080 Graduate Admission (30 分)
#include <iostream>#include <stdio.h>#include <vector>#include <algorithm>#include <stdlib.h>using namespace std;typedef struct Stu {原创 2019-01-16 11:13:52 · 267 阅读 · 0 评论 -
【PAT甲级】1051. Pop Sequence (25)
#include <stdio.h>#include <stack>#include <deque>using namespace std;int main(int argc, char *argv[]) { int m, n, k, a; scanf("%d %d %d", &m, &n, &k); while (k--) { stack<int> s;原创 2016-10-27 22:49:53 · 216 阅读 · 0 评论 -
【PAT甲级】1052. Linked List Sorting (25)
注:如果链表为空,输出 “0 -1”#include <stdio.h>#include <deque>#include <algorithm>#define INC 100000#define MAX 200001using namespace std;int main(int argc, char *argv[]) { int n, start; scanf("%d %原创 2016-10-28 00:34:11 · 318 阅读 · 0 评论 -
【PAT甲级】1053. Path of Equal Weight (30)
注:比较函数写得有点复杂#include <stdio.h>#include <deque>#include <algorithm>#include <cmath>using namespace std;typedef struct Node { int key; int left; int right;} Node;Node tree[101];int n,原创 2016-10-28 17:25:09 · 215 阅读 · 0 评论 -
【PAT甲级】1054. The Dominant Color (20)
#include <stdio.h>#include <vector>#include <algorithm>#define MAX 1<<26using namespace std;int color[MAX] = {0};bool cmp(int a, int b) { return color[a] > color[b];}int main(int argc, char原创 2016-10-28 17:39:18 · 218 阅读 · 0 评论 -
【PAT甲级】1055. The World's Richest (25)
注:本以为考察二分法,结果并不是( ´◔ ‸◔’)#include <stdio.h> #include <algorithm>#include <vector>#include <string.h>using namespace std;typedef struct People { char name[9]; int age; int worth;} Peop原创 2016-10-28 19:55:52 · 222 阅读 · 0 评论 -
【PAT甲级】1030. Travel Plan (30)
#include <stdio.h>#define MAX 9999999typedef struct Ci { int dist; int cost;} Ci;Ci map[501][501];int n, m, s, d;int main(int argc, char *argv[]) { scanf("%d %d %d %d", &n, &m, &s, &d);原创 2016-10-20 11:12:57 · 262 阅读 · 0 评论 -
【PAT甲级】1031. Hello World for U (20)
#include <stdio.h>#include <string.h>int main(int argc, char *argv[]) { int n, n1, n2, n3; char a[81]; scanf("%s", a); n = strlen(a); if (n % 2 == 0) n2 = 4; else n2 = 3; n原创 2016-10-20 11:41:11 · 268 阅读 · 0 评论 -
【PAT甲级】1026. Table Tennis (30)
注:vip顾客面临多桌选择时,优先选择vip球桌。注2:非vip顾客有多桌选择时,选id号最小的球桌。注3:只有vip桌空出来的时候,vip顾客才能插队;非vip球桌空出来时,顾客(包括vip与非vip)中到达最早的先选。#include <stdio.h>#include <deque>#include <algorithm>#define OPEN_TIME 8 * 3600#def原创 2016-10-19 21:11:54 · 315 阅读 · 0 评论 -
【PAT甲级】1025. PAT Ranking (25)
#include <stdio.h>#include <iostream>#include <deque>#include <algorithm>#include <string.h>using namespace std;typedef struct Testee { string num; int loca; int score; int rank;原创 2016-10-18 10:50:25 · 237 阅读 · 0 评论 -
【PAT甲级】1024. Palindromic Number (25)
#include <stdio.h>#include <stdio.h>#include <string.h>char in[200];int num[200] = {0};int k;void add(int *a, int &n);bool isPa(int *a, int n);int main(int argc, char *argv[]) { scanf("%s %d原创 2016-10-17 23:12:15 · 257 阅读 · 0 评论 -
【PAT甲级】1047. Student List for Course (25)
#include <stdio.h>#include <vector>#include <stdlib.h>#include <algorithm>using namespace std;int getId(char *a) { int sum = (a[0]-'A')*26*26*10+(a[1]-'A')*26*10+(a[2]-'A')*10+(a[3]-'0');原创 2016-10-26 18:28:44 · 265 阅读 · 0 评论 -
【PAT甲级】1048. Find Coins (25)
#include <stdio.h>int main(int argc, char *argv[]) { int n, m; int face[501] = {0}; //vector<int> v; scanf("%d %d", &n, &m); int i; for (i = 0; i < n; i++) { int tmp;原创 2016-10-26 19:08:57 · 188 阅读 · 0 评论 -
【PAT甲级】1049. Counting Ones (30)
#include <stdio.h>#include <cmath>int f(int a);int a[11] = {0};int main(int argc, char *argv[]) { int n; scanf("%d", &n); int i, j; int cnt = 0; int tmp = n; while (tmp > 0)原创 2016-10-26 22:58:48 · 199 阅读 · 0 评论 -
【PAT甲级】1050. String Subtraction (20)
#include <stdio.h>#include <string.h>int main(int argc, char *argv[]) { char a[10001]; char b[10001]; int map[1000] = {0}; gets(a); int al = strlen(a); gets(b); int bl = st原创 2016-10-26 23:23:33 · 268 阅读 · 0 评论 -
【PAT甲级】1014. Waiting in Line (30)
#include <stdio.h>#include <iostream>#include <string.h>#include <queue>#include <stdlib.h>using namespace std;typedef struct cus { int proTime; int serTime; int finTime;} Cus;int n,原创 2016-10-02 18:38:19 · 236 阅读 · 0 评论 -
【PAT甲级】1015. Reversible Primes (20)
注:1是非素数#include <stdio.h>#include <cmath>int getNumWithRadix(int n, int d);int getDecimal(int n, int d); int getReverse(int n);bool isPrime(int n);int main(int argc, char *argv[]) { int n, d;原创 2016-10-02 21:59:39 · 211 阅读 · 0 评论 -
【PAT甲级】1022. Digital Library (30)
#include <iostream>#include <iomanip>#include <sstream>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <string>#include <map>#include <set>using namespace std;int n;int m;m原创 2016-10-17 21:34:34 · 339 阅读 · 0 评论 -
【PAT甲级】1023. Have Fun with Numbers (20)
#include <stdio.h>#include <string.h>int main(int argc, char *argv[]) { int i, k; char in[23]; int num[23] = {0}; int map[10] = {0}; int map2[10] = {0}; scanf("%s", in); k原创 2016-10-17 22:39:09 · 222 阅读 · 0 评论 -
【PAT甲级】1006. Sign In and Sign Out (25)
#include <iostream>#include <stdio.h>#include <string.h>#include <string>using namespace std;typedef struct per { char ID[16]; int inTime; int outTime;} per;int main(int argc, char *ar原创 2016-09-26 18:54:01 · 292 阅读 · 0 评论 -
【PAT甲级】1027. Colors in Mars (20)
#include <stdio.h>char toChar(int i);int main(int argc, char *argv[]) { int a[3]; scanf("%d %d %d", &a[0], &a[1], &a[2]); int rgb[3][2]; int i; for (i = 0; i < 3; i++) { rgb原创 2016-10-19 22:35:36 · 239 阅读 · 0 评论 -
【PAT甲级】1072. Gas Station (30)
此题用Dijkstra计算;如果用Floyd最后一个测试用例会超时#include <stdio.h>#include <iostream> #include <vector>#include <string>#include <algorithm>#include <stdlib.h>#define INF 1<<29using namespace std;struct T {原创 2017-06-21 17:30:28 · 526 阅读 · 0 评论 -
【PAT甲级】1073. Scientific Notation (20)
#include <stdio.h>#include <iostream>#include <stdlib.h>#include <string>using namespace std;int main() { string input; getline(cin, input); int t = input.find('E', 0); string numbe原创 2017-06-21 21:08:46 · 232 阅读 · 0 评论 -
【PAT甲级】1074. Reversing Linked List (25)
#include <stdio.h>#include <iostream>using namespace std;struct Node { int e; int next;};Node list[100000];void swap(int *a, int i, int j);int main() { int start, len, k; cin >> sta原创 2017-06-22 16:53:02 · 290 阅读 · 0 评论 -
【PAT甲级】1075. PAT Judge (25)
注意:如果一名同学提交代码未通过编译,则他这道题成绩打印为0;如果他对某一题从未提交过代码,则他这道题成绩打印为‘-’;如果他提交的所有代码均未通过编译,则不打印他的成绩单。#include <stdio.h>#include <vector>#include <stdlib.h>#include <string.h>#include <algorithm>using namespac原创 2017-07-04 16:18:41 · 221 阅读 · 0 评论 -
【PAT甲级】1076. Forwards on Weibo (30)
#include <iostream>#include <vector>#include <stack>#include <stdlib.h>#include <string.h>using namespace std;int main() { int n, l; cin >> n >> l; vector<int> *v = new vector<int>[n +原创 2017-07-05 17:22:43 · 222 阅读 · 0 评论 -
【PAT甲级】1077. Kuchiguse (20)
注意:1. getline()可能get到空行,需要过滤一下2. 头文件algorithm中的reverse可以对字符串进行反转#include <iostream>#include <string>#include <vector>#include <algorithm>using namespace std;int findMinLength(vector<string> v);in原创 2017-07-06 16:13:10 · 214 阅读 · 0 评论 -
【PAT甲级】1078. Hashing (25)
二次探测法:探查序列为d=h(key),d+1^2,d+2^2,……#include <iostream>using namespace std;bool isPrime(int a);int findPos(int *a, int s, int msize);int main() { int msize, n; cin >> msize >> n; if (!isPr原创 2017-07-07 09:44:14 · 313 阅读 · 0 评论 -
【PAT甲级】1079. Total Sales of Supply Chain (25)
#include <stdio.h>#include <iostream>#include <vector>#include <stack>#include <math.h>using namespace std;int main() { int n; double p, r; cin >> n >> p >> r; vector<int> *v = new原创 2017-07-29 16:41:53 · 344 阅读 · 0 评论 -
【PAT甲级】1071. Speech Patterns (25)
#include <iostream>#include <string>#include <map>#include <cctype>using namespace std;int main() { string s, tmp; map<string, int> m; getline(cin, s); for (int i = 0; i < s.length(原创 2017-06-21 17:26:49 · 288 阅读 · 0 评论 -
【PAT甲级】1070. Mooncake (25)
#include <stdio.h>#include <algorithm>using namespace std;typedef struct Cake { double ton; double price; double up;} Cake;bool cmp(Cake a, Cake b) { return a.up > b.up;}int main(原创 2017-06-21 17:25:13 · 245 阅读 · 0 评论 -
【PAT甲级】1028. List Sorting (25)
#include <stdio.h>#include <deque>#include <string.h>#include <algorithm>using namespace std;typedef struct Stu { int id; char name[9]; int grade;} Stu;deque<Stu> student;bool com_i原创 2016-10-19 22:56:23 · 178 阅读 · 0 评论 -
【PAT甲级】1029. Median (25)
#include <stdio.h>#include <algorithm>#include <deque>using namespace std;deque<long> dq[2];deque<long> q;int main(int argc, char *argv[]) { for (int i = 0; i < 2; i++) { int m;原创 2016-10-19 23:29:58 · 210 阅读 · 0 评论 -
【PAT甲级】1016. Phone Bills (25)
注:如果一个用户所有通话记录均不匹配,则不打印他的任何信息#include <stdio.h>#include <string>#include <string.h>#include <vector>#include <algorithm>#include <iostream>using namespace std;typedef struct Rec { string name;原创 2016-10-08 12:36:08 · 386 阅读 · 0 评论 -
【PAT甲级】1032. Sharing (25)
注:这道题除了必要的输入数据外,还可能有杂七杂八的干扰,比如无用的链接、重复的链接等。#include <stdio.h>int main(int argc, char *argv[]) { int list[100000] = {0}; int n; int arr1; int arr2; int set[100000] = {0}; int i;原创 2016-10-20 20:46:47 · 271 阅读 · 0 评论 -
【PAT甲级】1066. Root of AVL Tree (25)
#include <stdio.h>#include <math.h>#include <stdlib.h>typedef struct Node { Node *left; Node *right; int key;} Node;void insert(Node* &r, int k);int height(Node *r);int max(int a, int原创 2016-11-11 17:29:53 · 368 阅读 · 0 评论 -
【PAT甲级】1067. Sort with Swap(0,*) (25)
注:第二个for循环中,始终从0开始查找会使测试用例1、2超时,因此作一个小优化,即记住上次开始查找的位置start,下次从此处开始进行查找。#include <stdio.h>void swap(int *a, int *pos, int x, int y) { int tmp = a[x]; a[x] = a[y]; pos[a[y]] = x; a[y] =原创 2016-11-14 15:09:34 · 388 阅读 · 0 评论 -
【PAT甲级】1056. Mice and Rice (25)
#include <stdio.h>#include <cmath>#include <string.h>#include <deque>using namespace std;int main(int argc, char *argv[]) { int np, ng; scanf("%d %d", &np, &ng); int i, j, k, in; in原创 2016-11-02 19:08:24 · 336 阅读 · 0 评论 -
【PAT甲级】1069. The Black Hole of Numbers (20)
#include <stdio.h>#include <algorithm>#include <math.h>using namespace std;bool cmp(int a, int b) { return a > b;}int getNum(int *a);int main(int argc, char *argv[]) { int in; int a[原创 2017-06-21 17:23:28 · 222 阅读 · 0 评论 -
【PAT甲级】1046. Shortest Distance (20)
#include <stdio.h>#include <cstdlib>using namespace std;int main(int argc, char *argv[]) { int n; int i, j, k; scanf("%d", &n); int *a = new int[n + 1]; a[0] = 0; for (i = 1; i原创 2016-10-26 15:52:29 · 218 阅读 · 0 评论