
PAT B
qq_52051345
博客转移至www.acming.net和51codefly.com
展开
-
1032 Sharing
题目传送门 分析:遍历第一个链表,标记每个节点为1,再遍历第二个链表,如果有被标记的节点就输出该地址,否则输出-1。#include <iostream>using namespace std;struct Node{ char key; int next; int flag;}node[1000005];int main(){ int s1, s2, n, a,...原创 2019-08-11 20:21:59 · 139 阅读 · 0 评论 -
1033 To Fill or Not to Fill
题目传送门 算法分析:① 首先增加一个目的地处的加油站,距离为目的地的距离,价格为0。题目要求最低价格那么先要考虑能不能到达目的地。有两种情况到不了目的地,第一种是所有的加油站距离都没有等于0的,那么说明车哪也去不了,直接输出并return;第二种是中途两个加油站之间的距离大于加满油后汽车能够行驶的最大距离,那么最大距离为当前加油站距离起点的距离加上汽车加满油能行驶最大距离。② 那么我们来考...原创 2019-08-11 20:25:08 · 122 阅读 · 0 评论 -
1051 Pop Sequence
题目传送门 分析:按顺序1~n把数字进栈,每进入一个数字,判断有没有超过最大范围,超过了就break。如果没超过,设cur = 1,从数组的第一个数字开始,看是否与栈顶元素相等,while相等就一直弹出栈。循环退出后,如过栈为空就输出YES,否则输出NO。#include <iostream>#include <vector>#include <stack&g...原创 2019-08-11 20:27:29 · 141 阅读 · 0 评论 -
1070 Mooncake
题目传送门 水。。#include <iostream>#include <algorithm>#include <vector> using namespace std;struct node{ double total, price, unit;};int cmp(node a, node b){ return a.unit >...原创 2019-08-11 20:29:15 · 132 阅读 · 0 评论 -
1084 Broken Keyboard
题目传送门 英文理解题…#include <iostream>#include <vector>#include <string> #include <algorithm>using namespace std;int main(){ string s, s0, ans; cin >> s >> s0; ...原创 2019-08-11 20:30:23 · 148 阅读 · 0 评论 -
1085 Perfect Sequence
题目传送门 分析:⾸首先将数列列从小到大排序,设当前结果为 ans = 0,当前最长长度为 t = 0;从i = 0~n,j从i + ans到n,每次计算 t 若大于ans则更新ans,最后输出result的值。#include <iostream>#include <vector>#include <algorithm>using namespace...原创 2019-08-11 20:34:03 · 102 阅读 · 0 评论 -
1074 Reversing Linked List
题目传送门 用一个数组来存储地址,然后反转这个数组,再输出就行了。 while (first != -1) { address[sum++] = first; first = next[first]; }#include <iostream>#include <algorithm>using namespace std;int main() {...原创 2019-08-12 10:39:07 · 105 阅读 · 0 评论 -
1048 Find Coins
题目传送门 算法分析:把硬币个数以及面值存放在一个数组中,遍历一次判断就完事。#include <iostream>using namespace std;int a[1005];int main(){ int n, m, t; scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) { sca...原创 2019-08-12 10:58:54 · 102 阅读 · 0 评论