随笔分类 -  PAT Advanced

摘要:对于一个序列,每输入一个数t,如果栈不为空,就判断它与栈顶是否相等,如果等,栈顶出栈,判断下一个数;如果不等,在栈的大小允许范围内,将index入栈,每入栈一次判断一次t与 栈顶是否相等。 如果序列是符合要求的,最后的栈一定是空的,所以只要在处理完序列后判断栈有没有空即可知道序列对不对。 1 int 阅读全文
posted @ 2021-03-05 17:37 幻想Elapse 阅读(30) 评论(0) 推荐(0) 编辑
摘要:非原创,参考:https://blog.csdn.net/richenyunqi/article/details/81150510 1 #pragma warning(disable:4996) 2 #define _CRT_SECURE_NO_WARNINGS 3 4 #include <iost 阅读全文
posted @ 2021-03-05 10:50 幻想Elapse 阅读(46) 评论(0) 推荐(0) 编辑
摘要:1 #pragma warning(disable:4996) 2 #define _CRT_SECURE_NO_WARNINGS 3 4 #include <iostream> 5 #include <algorithm> 6 #include <cmath> 7 #include <vector 阅读全文
posted @ 2021-03-04 21:37 幻想Elapse 阅读(53) 评论(0) 推荐(0) 编辑
摘要:第一个序列用vector存储起来,第二个序列读入时可同时处理(在线算法)。 需要得到的数(结果)是两个序列组合并后,处于下标(n+m-1)/2的数,所以for循环需要执行(n+m-1)/2次(每次确定一个数)。 最后输出s2[i-1]或者s2[(n+m-1)/2]即可。 注意此处的处理: 如果输入个 阅读全文
posted @ 2021-03-04 19:32 幻想Elapse 阅读(72) 评论(0) 推荐(0) 编辑
摘要:参考:https://blog.csdn.net/richenyunqi/article/details/78868563 1 #pragma warning(disable:4996) 2 #define _CRT_SECURE_NO_WARNINGS 3 4 #include <iostream 阅读全文
posted @ 2021-03-04 11:08 幻想Elapse 阅读(48) 评论(0) 推荐(0) 编辑
摘要:1 #pragma warning(disable:4996) 2 #define _CRT_SECURE_NO_WARNINGS 3 4 #include <iostream> 5 #include <algorithm> 6 #include <cmath> 7 #include <vector 阅读全文
posted @ 2021-03-03 10:50 幻想Elapse 阅读(53) 评论(0) 推荐(0) 编辑
摘要:使用dfs计算连通分量的数量 1 #pragma warning(disable:4996) 2 #define _CRT_SECURE_NO_WARNINGS 3 4 #include <iostream> 5 #include <algorithm> 6 #include <cmath> 7 # 阅读全文
posted @ 2021-03-02 22:17 幻想Elapse 阅读(58) 评论(0) 推荐(0) 编辑
摘要:先定义结构图node{name, height},存放姓名和身高。先将所有人按照身高顺序从大到小排好序(因为从最后一排开始输出,最后一排身高最高,所以刚好是从头开始处理),再分组处理,除了最后一排人数是n/k+n%k,其余排的人数均为n/k,引入formation函数,用下标作为参数给出处理范围(下 阅读全文
posted @ 2021-03-01 16:13 幻想Elapse 阅读(53) 评论(0) 推荐(0) 编辑
摘要:其实核心思想就是遍历每一个‘A’,这个A前面P的数量和后面T的数量的乘积就是一个A所能产生的PAT数,依次累加起来就是总的数量。 所以可以先找到第1个A,再找到第1个A前面所有P的数量cp,后面所有T的数量ct,相乘,并累加到结果中。 接着找第2个、第3个……第N个A,在找的过程中,如果遇到P,就将 阅读全文
posted @ 2021-03-01 10:57 幻想Elapse 阅读(45) 评论(0) 推荐(0) 编辑
摘要:1 #pragma warning(disable:4996) 2 #define _CRT_SECURE_NO_WARNINGS 3 4 #include <iostream> 5 #include <map> 6 #include <set> 7 using namespace std; 8 s 阅读全文
posted @ 2021-02-20 20:10 幻想Elapse 阅读(49) 评论(0) 推荐(0) 编辑
摘要:题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805357933608960 1 #pragma warning(disable:4996) 2 #define _CRT_SECURE_NO_WARNINGS 3 4 阅读全文
posted @ 2021-02-19 17:26 幻想Elapse 阅读(41) 评论(0) 推荐(0) 编辑
摘要:#include <iostream> #include <cstring> #include <algorithm> using namespace std; struct person { string id; int virtue, talent, sum; int type;//12345 阅读全文
posted @ 2020-09-30 10:10 幻想Elapse 阅读(103) 评论(0) 推荐(0) 编辑
摘要:注意事项: 八千万八千(√),八千万零八千(×) 输入为0时单独判断 #include <iostream> #include <cstring> using namespace std; int main() { char out_num[10][5] = { "yi","er","san","s 阅读全文
posted @ 2020-09-29 22:30 幻想Elapse 阅读(130) 评论(0) 推荐(0) 编辑
摘要:#include <iostream> #include <cstring> using namespace std; int main() { int N; cin >> N; char ch; int k = -1; char(*s)[300] = new char[101][300]; int 阅读全文
posted @ 2020-09-29 09:25 幻想Elapse 阅读(132) 评论(0) 推荐(0) 编辑
摘要:sort排序 #include <iostream> #include <algorithm> using namespace std; int main() { ios::sync_with_stdio(false); int N, M; cin >> N >> M; int* s = new i 阅读全文
posted @ 2020-09-28 23:04 幻想Elapse 阅读(70) 评论(0) 推荐(0) 编辑
摘要:#include <iostream> #include <cstring> using namespace std; int main() { char s[10000]; char res[10000]; cin >> s; int len = strlen(s); int pos = 0; w 阅读全文
posted @ 2020-09-28 16:26 幻想Elapse 阅读(100) 评论(0) 推荐(0) 编辑
摘要:1 #include <iostream> 2 #include <cstdio> 3 using namespace std; 4 int main() 5 { 6 string s; 7 cin >> s; 8 int N = s.size(); 9 int n1=(N+2)/3, n3 = ( 阅读全文
posted @ 2020-06-21 11:04 幻想Elapse 阅读(112) 评论(0) 推荐(0) 编辑
摘要:1 #include <iostream> 2 #include <cstdio> 3 using namespace std; 4 struct node 5 { 6 char name[20]; 7 char gender; 8 char id[20]; 9 int grade; 10 }; 1 阅读全文
posted @ 2020-06-21 10:23 幻想Elapse 阅读(144) 评论(0) 推荐(0) 编辑
摘要:17分代码(测试点1,3错误) 1 #include<iostream> 2 #include <vector> 3 using namespace std; 4 struct node 5 { 6 string num,arrive,leave; 7 }; 8 int main() 9 { 10 阅读全文
posted @ 2020-06-20 17:30 幻想Elapse 阅读(154) 评论(0) 推荐(0) 编辑
摘要:1 #include <iostream> 2 #include <cstdio> 3 using namespace std; 4 int main() 5 { 6 char r[3] = {'W','T','L'}; 7 double v[3][3],sum=1.0,d; 8 for(int i 阅读全文
posted @ 2020-06-20 14:51 幻想Elapse 阅读(118) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示