02 2020 档案
摘要://-rw-rw-r-- 2 zijiao zijiao 16 Feb 24 13:20 hello #include <stdio.h> #include <unistd.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl
阅读全文
摘要:Video by Tushar https://www.geeksforgeeks.org/binary-indexed-tree-or-fenwick-tree-2/ #include <bits/stdc++.h> # define LL long long using namespace st
阅读全文
摘要:link Solution: https://codeforces.com/blog/entry/74224 #include <bits/stdc++.h> # define LL long long using namespace std; string s; int main(){ int T
阅读全文
摘要:link Solution 1 gready: class Solution { public: string largestMultipleOfThree(vector<int>& digits) { multiset<int,greater<int>> one, two; int sum=0;
阅读全文
摘要:link class Solution { public: #define ll long long int mod=1E9+7; int uniqueLetterString(string S) { int n=S.size(); ll res=0; vector<int> last1(26,-1
阅读全文
摘要:1. OPEN umask=2, 666&(~2)=664 2. CLOSE 3. Read 4. write 模拟 cat: 需求: 写hello到一个文件,然后读取,输出到终端。 若这样写,read不到,因为写hello后将到文件末尾。 需要lseek lseek 计算文件大小 少了一句: cl
阅读全文
摘要:使用gdb: 编译时加-g参数 gcc -o app -I ./ func.c main.c -g 启动gdb: gdb app 在gdb启动程序: r(un) 启动 start 启动 停留在main函数,分步调试 n(ext) 下一条语句 s(tep) 下一条语句,可以进入到函数内部 q(uit)
阅读全文
摘要:makefile 三要素: 目标 依赖 规则命令 写法: 目标:依赖 规则命令 v1: 缺点: 如果更改其中一个文件,所有源码都需要重新编译 可以考虑编译过程分解,先生成.o文件,使用.o文件得到结果 v2: 这样做的话,如果改变main.c,只需重新编译main.c, add.c sub.c无需重
阅读全文
摘要:静态库文件命名: libxxx.a 制作步骤: 1. 编译为.o文件 2.将.o文件打包: ar rcs libxxx.a file1.o file2.o 3.将头文件与库一起发布 使用: gcc main.c -o app -I ./include/ -L lib/ -lxxx 动态库文件命名:
阅读全文
摘要:1. copy:yy (当前行) ,5yy(当前以及下面共五行) 正常模式下2. paste:p 正常模式下复制到光标下一行 P 复制到当前行 3. delete one line: dd, 5dd(5 lines) 正常模式下 4. x 删除光标位置内容 5. dw 删除一个单词 6. d$ 删除
阅读全文
摘要:Link /* // Definition for a Node. class Node { public: int val; vector<Node*> children; Node() {} Node(int _val) { val = _val; } Node(int _val, vector
阅读全文
摘要:Link Solution: f[i][j]= 1 if i cats can make up j blood. f[0][0]=1 #include <bits/stdc++.h> # define LL long long using namespace std; int n; int a[21
阅读全文
摘要:Link Solution: Get the posistions of numbers of P2 in P1, find the LIS in this position array. #include <bits/stdc++.h> # define LL long long using na
阅读全文
摘要:Link class Solution { public: int lengthOfLIS(vector<int>& nums) { int n=nums.size(); if(n==0) return 0; vector<int> dp(n+1); int len=1; dp[1]=nums[0]
阅读全文
摘要:Link Solution: ans=sum of total triangles - sum of triangles with different colors Define the angle with different edge as D-angle. Consider triangles
阅读全文
摘要:Link Solution 1 Hungarian: class Solution { public: int m,n; vector<vector<int>> g; vector<vector<int>> dir={{0,-1},{-1,-1},{1,-1},{0,1},{-1,1},{1,1}}
阅读全文
摘要:Link #include <bits/stdc++.h> # define LL long using namespace std; const int mod=100000000; int M, N; int grid[12]; LL dp[12][1<<12]; LL dfs(int r, i
阅读全文
摘要:Link #include <bits/stdc++.h> # define LL long using namespace std; const int INF=0x7fffffff; int n; double x[16]; double y[16]; double dp[17][1<<16];
阅读全文
摘要:Link Solution 0: class Solution { public: int m,n; int maxStudents(vector<vector<char>>& seats) { m=seats.size(); n=seats[0].size(); vector<vector<int
阅读全文
摘要:Link class Solution { public: int ladderLength(string beginWord, string endWord, vector<string>& wordList) { unordered_set<string> words; for(auto &s:
阅读全文
摘要:link class Solution { public: vector<vector<string>> findLadders(string beginWord, string endWord, vector<string>& wordList) { vector<vector<string>>
阅读全文
摘要:题目链接 题解: 如果不考虑长度限制,可以用二分图染色做。 #include <bits/stdc++.h> # define LL long using namespace std; int n; int a[2001]; int col[2001]; struct Edge{ int to; i
阅读全文
摘要:题目链接 和leetcode一道题很像。。。 #include <bits/stdc++.h> # define LL long using namespace std; const int INF=0x7fffffff; const int maxn=50002; int n; int f[max
阅读全文
摘要:#include <bits/stdc++.h> # define LL long long using namespace std; const int INF=0x7fffffff; int n, m; struct Trie{ bool isword; int cnt; Trie* child
阅读全文
摘要:题目链接 题解: 这道题太复杂了。。。主要是前两列最开始比较难想怎么做。 # Write your MySQL query statement below select t4.spend_date, t4.platform, if(t6.spend_date is null,0,t6.amount)
阅读全文
摘要:题目链接 题解1: 先排序,然后用自定义变量记录累计的score。 select gender,day,total from( select day, @s:=(if(gender=@g,@s+score_points,score_points)) as total, @g:=gender as g
阅读全文
摘要:题目链接 题解: 先用所有的边生成一棵最小生成树,然后从后往前不断删边,看此边有没有用到,用到的话重新跑生成树,没有的话结果不变。还是Kruskal方便些。。。 Prime: #include <bits/stdc++.h> # define LL long long using namespace
阅读全文
摘要:题目链接 题解: 每一个子连通图,对它进行黑白染色,然后取两种染色中的最小值,然后最后汇总。 #include <bits/stdc++.h> # define LL long long using namespace std; const int maxn=10000+10; const int
阅读全文
摘要:题目链接 题解: 方法1: 走一遍dfs/bfs得到u->v的路径。每一个m,保证走过得边>=此最小值。再走一遍m,看路径的最小值是否是提供的。 #include <bits/stdc++.h> # define LL long long using namespace std; int n; in
阅读全文
摘要:题目链接 解法: 栈 1 #include <bits/stdc++.h> 2 # define LL long long 3 using namespace std; 4 5 const int mod=10007; 6 stack<char> ope; 7 stack<int> one; 8 s
阅读全文
摘要:题目链接 1 #include <bits/stdc++.h> 2 # define LL long long 3 using namespace std; 4 5 const int maxn=5000+10; 6 int n; 7 LL dis[maxn]; 8 int complete[max
阅读全文
摘要:题目链接 题目描述 输入k及k个整数n1,n2,…,nk,表示有k堆火柴棒,第i堆火柴棒的根数为ni;接着便是你和计算机取火柴棒的对弈游戏。取的规则如下:每次可以从一堆中取走若干根火柴,也可以一堆全部取走,但不允许跨堆取,也不允许不取。 谁取走最后一根火柴为胜利者。 编一个程序,在给出初始状态之后,
阅读全文
摘要:Link Solution: O(n2): 1 #include <bits/stdc++.h> 2 # define LL long long 3 using namespace std; 4 const int INF=0x7fffffff; 5 int n, m, k; 6 int arr[3
阅读全文
摘要:题目链接 1 #include <bits/stdc++.h> 2 # define LL long long 3 using namespace std; 4 5 bool dfs(vector<int> &num, vector<string> &res){ 6 if(num.size()==1
阅读全文
摘要:题目链接 题解: 我们可以对棋盘进行黑白染色,使得任意相邻的两个格子颜色不相同,然后进行二分图最大匹配。 Code: 1 class Solution { 2 public: 3 int N; 4 int M; 5 6 vector<vector<int>> dir{{1,0},{0,1},{-1,
阅读全文
摘要:题目链接 Code: 1 class Solution { 2 public: 3 int sub; 4 int assignBikes(vector<vector<int>>& workers, vector<vector<int>>& bikes) { 5 int N=workers.size(
阅读全文
摘要:题目链接 Code: 1 #include <bits/stdc++.h> 2 3 using namespace std; 4 5 6 const int N=301; 7 int n; 8 int grid[N][N]; 9 int expx[N]; 10 int expy[N]; 11 int
阅读全文
摘要:Code: 1 #include<bits/stdc++.h> 2 using namespace std; 3 4 void manacher(string &ss, vector<int> &leftPart){ 5 vector<int> t(ss.size(),0); 6 int middl
阅读全文
摘要:题目链接 题解: 对每种主件的 附件的集合 进行一次 01 背包处理,就可以先求出 对于每一种主件包括其附件的组合中,每种花费的最大价值,对应不同的方案。 在对主件进行背包处理。 需要注意的是在对每个主件的附件进行处理时,要恰好花完价钱,否则方案数会非常多。 Code: 1 #include <bi
阅读全文
摘要:题目链接 Code: 1 #include <bits/stdc++.h> 2 # define LL long long 3 using namespace std; 4 5 const int maxn=100+10; 6 int N; 7 int val[maxn]; 8 int dp[max
阅读全文
摘要:题目链接 Code: 1 class Solution { 2 public: 3 int maxCoins(vector<int>& nums) { 4 vector<int> arr; 5 arr.push_back(1); 6 for(int i:nums){ 7 arr.push_back(
阅读全文
摘要:题目链接 题解: copy from: https://www.luogu.com.cn/blog/ryoku/ryoku-di-xin-nian-huan-le-sai-ti-xie segment tree, seg[i]为区间元素个数,每次从剩下的数中找第(b[i]+1)小的数,然后去掉次数(
阅读全文