
PAT
kiss_the_rain86
这个作者很懒,什么都没留下…
展开
-
堆的建立、调整和排序
#include<vector>#include<iostream>#include<queue>#include<vector>using namespace std;const int maxn = 100;//int heap[maxn];int n = 10;void downAdjust(int low, int high) { int i = low, j = i * 2;//欲调整节点与其左孩子。 while (j &原创 2020-09-17 16:01:29 · 289 阅读 · 0 评论 -
树相关(二叉树、多叉树、二叉查找树、平衡二叉树)
基本操作原创 2020-09-06 17:50:18 · 162 阅读 · 0 评论 -
搜索相关
DFS搜索背包问题背包有容量(重量)每件物品有自己的价值和重量物品取或不取两种情况const int maxn = 30;int n, V, maxValue = 0;//物品件数n、背包容量V、最大价值maxValueint w[maxn], c[maxn];//每件物品的重量和价值void dfs(int index, int sumW, int sumC) { if (index == n) { if (sumW<V && sumC>maxVal原创 2020-09-02 22:02:24 · 160 阅读 · 0 评论 -
链表相关(基本操作+翻转链表+奇偶分类+回文链表判断)
链表基本操作创建链表头节点只有next 数据域无内容,一开始赋值给pre有一个pre,用来连接新生成的节点用new生成新节点每次循环更新当前节点为pre节点#include<vector>#include<iostream>using namespace std;struct node { int data; node* next;};//创建链表node* create(vector<int> &arr) { node *p原创 2020-08-31 11:51:15 · 207 阅读 · 0 评论 -
一般贪心,区间贪心
月饼,贪心策略是单价。#include "pch.h"#include <cstdio>#include<algorithm>using namespace std;const int maxn = 10000;struct Mooncake { double store;//库存量 double sell;//售价 double price;//单价}mooncake[maxn];int N;double need;//种类、最大需求bool cm原创 2020-08-22 17:54:10 · 160 阅读 · 0 评论 -
递归分治(斐波那契数列、全排列、n皇后)
求斐波那契数列第n项的值#include <cstdio>int F(int n) { if (n == 0 || n==1) return 1; else { return F(n - 1) + F(n - 2); }}int main() { int n; scanf("%d", &n); int re = F(n); printf("%d", re); return 0;}全排列const int maxn = 11;int n, P[原创 2020-08-15 10:27:34 · 368 阅读 · 0 评论 -
关于散列
一个统计程序。计算M数组中每个数在N数组中出现的次数。我们建一个表,在输入M数组内容的时候,对表中数据进行更新,而且直接将输入的数字作为表的index。#include <cstdio>const int maxn = 100010;int hashTable[maxn] = { 0 };int main() { int n, m, x; scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) { scanf原创 2020-08-13 21:23:30 · 117 阅读 · 0 评论 -
一些数学问题——公约数公倍数、质数判断、质因数分解
最大公约数与最小公倍数最大公约数辗转相除法:int gcd(int a,int b){ if(b==0) return a; else return gcd(b,a%b);}最小公倍数在求出a b的最大公约数d之后,可以马上得到a b的最小公倍数是ab/d素数素数的判断判断一个数字从2到其根号是否能被它整除bool isPrime(int n) { if (n <= 1)return false; int sqr = (int)sqrt(1.0*n); for (int原创 2020-07-23 21:26:19 · 289 阅读 · 0 评论 -
C++STL应用
vector访问,下标和迭代器两种方式注意在STL中,只要vector和string允许vi.begin()+3这种迭代器加上整数的写法#include<vector>#include<iostream>using namespace std;//访问vector 下标/迭代器int main() { vector<int> vi; for (int i = 0; i <= 5; i++) { vi.push_back(i); }原创 2020-07-19 22:09:10 · 360 阅读 · 1 评论 -
二分法的三种查找情况,快速幂
//在一个言给递增序列中找出给定数xint binarySearch(int A[], int left, int right,int x) { int mid; while (left <= right) { mid = left + (right - left) / 2; if (A[mid] == x)return mid; else if (A[mid] > x) right = mid - 1; else left = mid + 1; } return -1原创 2020-07-19 09:53:19 · 189 阅读 · 0 评论 -
1043 Is It a Binary Search Tree (25分)
搜索二叉树的创建和遍历问题。重难点是搜索二叉树的建立。#include<iostream>#include<vector>using namespace std;struct node { int val; node* lchild; node* rchild;};const int maxn = 1005;int n;vector<int> inputA;vector<int> pre;//先序vector<int&g.原创 2020-06-02 21:27:24 · 107 阅读 · 0 评论 -
1013 Battle Over Cities (25分)
寻找图中的连通量。对图中的节点进行dfs即可。如果用cin,最后一个用例会超时。参考:https://blog.youkuaiyun.com/qq_31785871/article/details/51817237#include <iostream>using namespace std;int N, M, K;//N:城市总数,道路总数,检查数int aja[1005][1005] = { 0 };//邻接矩阵 1代表有边int taja[1005][1005] = { 0 };//邻接.原创 2020-05-27 21:23:16 · 131 阅读 · 0 评论 -
1075 PAT Judge (25分)谁能告诉我最后一个测试点错哪谢人民币5元
这题要考虑的细节太多了,实不相瞒我做吐了,并不难,就是要考虑很多细节一遍遍调,,,还没全通过,,2,4测试点待解决,,太菜了#include<iostream>#include<vector>#include<iomanip>#include<algorithm>#include<cstring>using namespace std;struct Stu { int id = 0;//为0是默认。 int rank = 0;原创 2020-05-24 23:31:39 · 214 阅读 · 0 评论