
杂谈笔记
带有总结性的一些垃圾小文章~
_Hsiung
这个作者很懒,什么都没留下…
展开
-
getline函数不是每次从头读取
当ifstream File(filename);只要不关闭(file.close)这个文件都会继续往下读多个文件同时读取ifstream Files[9];Files[i].open(FileName, ios::in);原创 2021-05-27 17:04:41 · 245 阅读 · 0 评论 -
C++/QT 逐行获取文件内容操作
记录一下 ,每次都忘很烦C++数据类似这样的头文件:#pragma once#include <fstream>#include <iostream>#include <vector>#include <string>using namespace std;double Vertx[20], Verty[20];ifstream MyFile("E:\\大二下\\上机代码\\算法课设上机\\SatCoverInfo_0.txt");v原创 2021-05-18 17:16:06 · 661 阅读 · 0 评论 -
String类+KMP
```cpp#include <stdio.h>#include <string.h> #include <stdlib.h> typedef int Position;#define NotFound -1 void BuildMatch( char *pattern, int *match ){ Position i, j; int m = strlen(pattern); match[0] = -1; f原创 2020-10-15 21:29:20 · 146 阅读 · 0 评论 -
多项式 秦九韶算法
求a0+a1x+a2x^ 2+…anx^ n数组a存系数int QinJiuShao(int n,double a[], int x){ int i; double p = a[n]; for (i = n; i > 0; i--) { p = a[i-1] + x * p; } return p;}原创 2020-10-07 16:49:05 · 329 阅读 · 0 评论 -
最小堆
#include<iostream>#include<queue> //试着加加constusing namespace std;const int defaultSize=10;template<class T>class MinHeap{public: MinHeap(int sz = defaultSize); MinHeap(T arr[], int n); ~MinHeap() { delete[] heap; } bool push(co原创 2020-10-05 20:14:47 · 107 阅读 · 0 评论 -
最大和分治+在线更新+记录位置
#include<iostream>using namespace std;int a[1000000];int max3(int a, int b, int c){ if (a > b) { if (a > c) return a; else return c; } else { if (b > c) return b; else return c; }}int fenzhi(int a[], int left,原创 2020-09-20 22:53:35 · 95 阅读 · 2 评论 -
删除在链表区间值的元素
#include<iostream>using namespace std;#include<vector>struct node{ int data; node* next;};typedef node* list;list init(){ list a = new node; a->next = NULL; return a;}list insert(list a,int i,int x){ list p = a; for (int k原创 2020-09-19 21:34:41 · 351 阅读 · 0 评论 -
两个带有头结点递增链表合并成一个递减链表 而且不能借助其他空间
#include<iostream>using namespace std;#include<vector>struct node{ int data; node* next;};typedef node* list;list reverse(list a){ list pre = NULL, cur = a->next; list temp; while (cur != NULL) { temp = cur->next; cur-&g原创 2020-09-19 20:14:41 · 174 阅读 · 0 评论 -
vector 解决约瑟夫环问题
总共 n个人 从s号开始,m个删去一个#include<iostream>#include<vector>using namespace std;int main(){ vector<int>v; int n, s, m; cin >> n >> s >> m; for (int i = 1; i <= n; i++) { v.push_back(i); } auto it = v.begin() +原创 2020-09-19 16:04:26 · 678 阅读 · 0 评论 -
用首位相接的数组仿stl双端队列deque
这是stl deque的测试 仅实现部分功能这是利用首位相接的数组 [循环队列]仿stl双端队列deque将得到一样的结果#include<iostream>#include<unordered_map>using namespace std;template<class T>class Deque{ int start, rear; T* elements; int maxsize ;public: Deque(); ~Deque()原创 2020-09-16 14:39:23 · 106 阅读 · 0 评论 -
迷宫选路[递归和递推]
#include<iostream>using namespace std;int m, n; //终点坐标struct node{ int x, y;};int map[5][3];int mark[5][3];node Node[8] = { {-1,0},{-1,1},{0,1},{1,1},{1,0},{1,-1},{0,-1},{-1,-1}};bool seekPath(int x, int y){ int xx, yy; if (x == m &.原创 2020-09-14 22:12:50 · 159 阅读 · 0 评论 -
STL stack
#include<iostream>#include<stack>using namespace std;template<class T>class Stack{ T* elements; int topPtr; int maxsize;public: Stack(int size = 50); ~Stack(){ delete[]elements; } void push(const T&x); void pop(); T top(原创 2020-09-14 16:56:10 · 80 阅读 · 0 评论 -
不会递归?五道例题教你如何递归
递归的适用范围代替多重循环用递归解决递归形式的问题用递归将问题分解为规模更小的子问题汉诺塔问题#include<iostream>using namespace std;void digui(int n,char a, char b, char c){ if (n == 1) { cout << a << "->" << c << endl; return; } digui(n - 1, a, c, b);原创 2020-08-23 17:26:00 · 223 阅读 · 0 评论 -
vector 插入实现
#include<iostream>#include<vector>#include<map>#include<string>#include<cstring>#include<cstdio>#include<algorithm>#include<set>#include<queue>#include<unordered_map>#include<cmath>原创 2020-08-20 18:16:47 · 341 阅读 · 0 评论 -
重载类型转换运算符 [隐式显式转换]
#include<iostream>#include<vector>#include<map>#include<string>#include<cstring>#include<cstdio>#include<algorithm>#include<set>#include<queue>#include<unordered_map>#include<cmath&g.原创 2020-08-20 10:55:38 · 211 阅读 · 0 评论 -
实现一个可变长数组
#include<iostream>#include<vector>#include<map>#include<string>#include<cstring>#include<cstdio>#include<algorithm>#include<set>#include<queue>#include<unordered_map>#include<cmath&g.原创 2020-08-20 08:59:32 · 361 阅读 · 0 评论 -
最大回文子串长度 [dp]
dp 将复杂度降到n平方#include<iostream>#include<vector>#include<queue>#include<stack>#include<string>#include<math.h>#include<algorithm>#include<map>#include<cstring>#include<set>using namespace原创 2020-08-05 22:40:37 · 146 阅读 · 0 评论 -
数塔问题(递归/递推)
递归写法 从上往下#include<iostream>#include<vector>#include<queue>#include<stack>#include<string>#include<math.h>#include<algorithm>#include<map>#include<cstring>#include<set>using namespace s原创 2020-08-04 12:57:57 · 1143 阅读 · 0 评论 -
大整数的四则运算
int 表示的数据范围有限,当涉及大整数的运算时候,我们就只能借助数组来存储,借助数组就依靠手工加减乘除,就小学学的那种来运算,然后一个个存入。先来个结构体bign,含有一个数组和数组长度。我们用字符串读入的数字可以存入bign。头尾颠倒存入,因为模拟手工加减乘这三个都是从低位开始的,颠倒后方便操作bign change(char str[]){ bign a; a.len = strlen(str); for (int i = 0; i < a.len; i++) { a.d[i]原创 2020-07-16 16:54:40 · 252 阅读 · 0 评论 -
又谈进制转换
#include<iostream>using namespace std;int Qtoten(int number,int p){ int product=1,x=0; while(number!=0) { x=x+(number%10)*product; number=number/10; product*=p; } return x;}void temtoQ(int number,int p){ int temp[40],count=0,num=0;原创 2020-07-16 09:28:06 · 92 阅读 · 0 评论 -
100的阶乘[大整数阶乘]
#include<iostream>using namespace std;int x[1000] = {0};int main() { x[0] = 1; int i, j, k = 1; int temp = 1; for (i = 2; i <= 50; i++) { for (int j = 0; j < k; j++) { x[j] = i * x[j];//2*1 3*2 4*6 } for (j = 0; j < k; j原创 2020-07-15 10:15:06 · 518 阅读 · 0 评论 -
最大公约数/最小公倍数
#include <iostream>using namespace std;int main(){ int a, b, temp1, temp2; int c; cout << "请按从大到小的顺序两个数字" << endl; cin >> a >> b; temp1 = a, temp2 = b; while (temp2 != 0) { c = temp1 % temp2; temp1 = temp2; te.原创 2020-07-14 19:54:32 · 104 阅读 · 0 评论 -
对于归并排序递归的理解
void merge(int a[], int l1, int r1, int l2, int r2){ int i = l1, j = l2; int temp[100], index = 0; while (i <= r1 && j <= r2) { if (a[i] <= a[j]) temp[index++] = a[i++]; else temp[index++] = a[j++]; } while (i <= r1) .原创 2020-07-12 11:14:06 · 316 阅读 · 0 评论 -
快速幂
为什么要用快速幂因为当指数很大的时候,暴力的求幂函数的方式导致复杂度非常高。因此要采用降低复杂度的方式,称作快速幂。复杂度都是log2N思想二分法思想用递归 比如2的10次方拆成两个2的5次方相乘 2的5次方再拆成2*2的4次方,2的四次方再拆成2的2次方 一直到指数为0。用迭代typedef long long LL;//递归写法LL binarypow1(LL a, LL b, LL m){ if (b == 0) return 1; if (b % 2 == 1) r原创 2020-07-11 11:21:25 · 170 阅读 · 0 评论 -
[转] 二分法求外接圆最大半径
[转]https://blog.youkuaiyun.com/flashmsn/article/details/94642687题目描述:给出N个线段长度,试将它们头尾相接组合成一个凸多边形,使凸多边形的外接圆(多边形每个顶点都在圆上)的半径最大,求该最大半径。其中N<=10^5,线段长度均不超过100,要求算法中不涉及坐标的计算。思路:二分算法的本质就是通过不断迭代使left 和 right 在固定条件下逐渐靠近真实值,符合一定误差,所以实际上把该题放在二分扩展里面,这个所谓的最大半径的“最大”是不在求转载 2020-07-11 09:40:31 · 448 阅读 · 0 评论 -
木棒切割问题 [二分]
#include<iostream>#include<cstring>#include<algorithm>#include<string>using namespace std;int main(){ int n, k; cin >> n; int a[1000]; for (int i = 0; i < n; i++) { cin >> a[i]; } cin >> k; sort(.原创 2020-07-11 08:57:52 · 440 阅读 · 0 评论 -
八皇后问题 [回溯]
#include<iostream>#include<cstring>#include<algorithm>#include<string>int n, p[9], hashtable[9] = { 0 }, num = 0;using namespace std;void digui(int index){ if (index == n + 1) { num++; return; } for (int x = 1; x <原创 2020-07-08 22:03:26 · 101 阅读 · 0 评论 -
3个数的全排列 [递归]
#include<iostream>#include<cstring>#include<algorithm>#include<string>int n, p[10], hashtable[10] = { 0 };using namespace std;void digui(int index){ if (index == n + 1) { for (int i = 1; i <=n; i++) { cout <<原创 2020-07-08 20:22:29 · 1874 阅读 · 0 评论 -
刷PAT的一些思考—Day 1
处理很多输入数据的时候可以边输入边处理,没必要读完了在处理可以简化很多。建立一个很大的桶像桶排序一样往里放数据这样可能更好解决问题。原创 2020-06-20 14:47:29 · 135 阅读 · 0 评论 -
关于scanf 使用return或者break退出时候读取有残留的问题
想了挺久的,scanf读取不完全的问题,所以使用return的时候要注意是否会对下一次循环有影响,return 和break等同效果在这。#include<iostream>using namespace std;int flag=1;int test(int v[4]){ for(int i=0;i<4;i++){ scanf("%d",&v[i]...原创 2020-04-15 20:42:14 · 193 阅读 · 0 评论