
【基础算法】
也可视作个人学习C++算法的学习笔记
WA的一声哭了出来
这个人很懒,但也写了一点东西。
展开
-
复习-使用vector写邻接表
思路:dfs找到x和y与所有点的距离,且x对于某个点的距离一定要大于y对那个点的距离(即为x在y“后面”追);#include <bits/stdc++.h>using namespace std;int n,x,y;void dfs(vector<vector<int> > &g, vector<int> &d, int u, int fa, int step){ for(auto v: g[u]) { .原创 2022-03-11 20:41:24 · 492 阅读 · 0 评论 -
2020.11.25大二练习:单调栈
文章目录[A: Bad Hair Day](http://poj.org/problem?id=3250)A: Bad Hair Day看到题目首先想到的肯定是朴素方法给每个牛都模拟一遍找,不过这样铁定TLE;这里可以换个思路:想要求每个牛能在其右边的一个连续序列中有多少比自己矮的数量,可以转换成求每个牛的左边有多少牛能看到自己,范围是一个均大于自身的、从左至右的递减序列。这样就可以用单调栈来求解了:#include <iostream>using namespace std;ty原创 2021-03-29 19:51:00 · 89 阅读 · 0 评论 -
C:大数的乘法
例如:#include <stdio.h> #include <stdlib.h>#include <string.h>void mul(char *a, char *b){ int i, j, na, nb, *s, fa = 1, fb = 1; if (a[0] == '-') //判断符号 { a++; fa = -1; } if (b[0] == '-') {原创 2020-05-14 16:20:46 · 242 阅读 · 0 评论