自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

朝气蓬勃

码农的自我修炼

  • 博客(76)
  • 资源 (2)
  • 收藏
  • 关注

转载 hiho 57 高斯消元 二

问题http://hihocoder.com/problemset/problem/1196?sid=785572解法转换成异或表达式, 然后使用高斯消元的到解。#include <bits/stdc++.h>using namespace std;enum{maxn = 30, n=5, m=6};int a[maxn][maxn];int b[maxn];int delt[5][2]

2016-04-29 23:14:43 214

原创 hiho 60. Permutation Sequence

问题https://leetcode.com/problems/permutation-sequence/解法复杂度o(n^2)class Solution {public: string getPermutation(int n, int k) { bool flag[n+1]; int f = 1; for (int i=1; i<=n;

2016-04-29 18:54:51 223

原创 leetcode 56. Merge Intervals

问题https://leetcode.com/problems/merge-intervals/解法首先按照start 排序, 逐个插入,如果与最后一个相交则合并,否则插入新节点。/** * Definition for an interval. * struct Interval { * int start; * int end; * Interval() : s

2016-04-29 16:46:34 211

原创 Leetcode 57. Insert Interval

问题https://leetcode.com/problems/insert-interval/解法要插入的段 newInterval 与原有的intervals 会相互重叠一部分。 首先找到重叠的左右边界,插入即可。/** * Definition for an interval. * struct Interval { * int start; * int end;

2016-04-29 16:26:20 256

原创 hiho 54 连通性·三

问题http://hihocoder.com/contest/hiho54/problem/1解法首先使用tarjan 求出强连通分量,将强连通分量看做一个节点,就消除了图中的环, 然后使用拓扑排序寻找一条权值最大的路径。#include <bits/stdc++.h>using namespace std;enum{maxn = 20000+4};vector<int> G[maxn];v

2016-04-29 10:23:01 227

转载 hiho 53 连通性二·边的双连通分量

问题http://hihocoder.com/problemset/problem/1184?sid=785059解法Tarjan算法+ 栈#include <bits/stdc++.h>using namespace std;enum{maxn = 20000+4};vector<int> G[maxn];int n;int parent[maxn];int low[maxn];in

2016-04-28 21:59:41 304

转载 hiho 52 连通性一·割边与割点

问题http://hihocoder.com/problemset/problem/1183?sid=785036解法#include <bits/stdc++.h>using namespace std;enum{maxn = 20000+5};vector<int> G[maxn];int visit[maxn];int low[maxn];int dfn[maxn];int pa

2016-04-28 21:56:41 283

转载 hiho 51 欧拉路·三

问题http://hihocoder.com/problemset/problem/1182?sid=784688解法构造有向图,每条边表示0~2n−12^n-1 中的一个数,则求有向图的欧拉回路。 使用Fleury算法 后path倒序输出才是结果。#include <bits/stdc++.h>using namespace std;enum{maxn = 1<<15};int G[max

2016-04-28 21:54:02 251

转载 hiho 50 Fleury算法求欧拉路径

问题http://hihocoder.com/problemset/problem/1181?sid=784004解法伪代码DFS(u): While (u存在未被删除的边e(u,v)) 删除边e(u,v) DFS(v) End PathSize ← PathSize + 1 Path[ PathSize ] ← u#include <

2016-04-28 21:45:12 367

转载 hiho 49 欧拉路·一

问题http://hihocoder.com/problemset/problem/1176?sid=783791解法 给定无孤立结点图G,若存在一条路,经过图中每边一次且仅一次,该条路称为欧拉路。 一个无向图存在欧拉路当且仅当该图是连通的且有且只有2个点的度数是奇数,此时这两个点只能作为欧拉路径的起点和终点。 若图中没有奇数度的点,那么起点和终点一定是同一个点,这样的欧拉路叫做欧拉

2016-04-28 21:41:08 248

原创 LeetCode 50. Pow(x, n)

问题https://leetcode.com/problems/powx-n/解法计算出2的幂次个x相乘的结果,然后将n分解成2的幂次,使用log(n)次即可求得结果。class Solution {public: double myPow(double x, int n) { if (x ==0.0 && n == 0) return 0.0/0.

2016-04-26 20:56:00 220

转载 LeetCode 49. Group Anagrams

问题https://leetcode.com/problems/anagrams/代码使用hash + set class Solution {public: vector<vector<string>> groupAnagrams(vector<string>& strs) { unordered_map<string, multiset<string>> mp;

2016-04-26 20:30:20 203

原创 LeetCode 45. Jump Game II

问题https://leetcode.com/problems/jump-game-ii/解法贪心法, 首先使用一个堆栈记录跳转路径,从后往前走(参考上一篇), 不断加入新节点,如果新节点可以跳过栈顶节点而到达栈的其他节点,则删除之间的节点。这样得到的路径总是比之前的路径短。class Solution {public: int jump(vector<int>& nums) {

2016-04-26 10:32:13 227

原创 Leetcode 55. Jump Game

问题https://leetcode.com/problems/jump-game/解法贪心法: now 表示要到达最后一个位置,至少要到达的位置。如果有位置i可以到达now则now = i;从后向前扫描如果now==0 则表示可以从0处到达最后一个位置。class Solution {public: bool canJump(vector<int>& nums) { i

2016-04-26 10:02:16 205

原创 Leetcode 44. Wildcard Matching

问题https://leetcode.com/problems/wildcard-matching/解法一(DP)复杂度O(n*m)与正则匹配dp实现相同 参考: http://blog.csdn.net/galaxy_wolf/article/details/51111906class Solution {public: bool isMatch(string s, string p

2016-04-25 10:54:23 239

转载 hiho 47 48 拓扑排序

问题http://hihocoder.com/problemset/problem/1174?sid=782321 http://hihocoder.com/contest/hiho48/problem/1代码首先找出所有入度为0的节点加入队列 1,每次从队列中拿出一个入度为0的节点,删除这个节点和其边 2,将入度为0的点加入队列。 重复1,2 直到队列为空。#include <bits/s

2016-04-24 22:44:25 230

转载 hiho 46 博弈游戏·Nim游戏·三

问题http://hihocoder.com/problemset/problem/1173代码Sprague-Grundy#include <bits/stdc++.h>using namespace std;int main(){ int n; scanf("%d", &n); int ret =0; for(int i=0; i<n; ++i) {

2016-04-24 17:44:11 225

转载 hiho 45 博弈游戏·Nim游戏·二

问题http://hihocoder.com/contest/hiho45/problem/1代码将局面划分成多个子局面,转化成Nim游戏#include <bits/stdc++.h>using namespace std;int main(){ int n; scanf("%d", &n); getchar(); int ret =0; for(in

2016-04-24 15:31:05 216

转载 hiho 44 博弈游戏·Nim游戏

问题http://hihocoder.com/contest/hiho44/problem/1代码博弈论中的Nim游戏是经典的公平组合游戏(ICG)#include <bits/stdc++.h>using namespace std;int main(){ int n; int a =0; scanf("%d", &n); int ret =0; fo

2016-04-24 14:13:55 212

转载 leetcode 42. Trapping Rain Water

问题https://leetcode.com/problems/trapping-rain-water/代码class Solution {public: int trap(vector<int>& height) { int L = 0; int R = height.size()-1; int ret = 0; int m

2016-04-23 23:18:40 193

原创 设计模式

http://blog.csdn.net/lovelion/article/details/17517213

2016-04-23 16:52:36 165

原创 c++ 读书目录

google c++ style guide http://zh-google-styleguide.readthedocs.org/en/latest/google-cpp-styleguide/

2016-04-23 10:03:44 225

原创 图形学博客

Alex Nankervis http://www.naixela.com/alex/

2016-04-22 17:20:42 298

转载 leetcode 41 First Missing Positive

问题https://leetcode.com/problems/first-missing-positive/代码将数字放到对应的下标处。 比如1 放在nums[0] 2 放在nums[1] 通过交换实现, 由于每个下标处放特定数,所以交换次数最多为n。 最后统计每一位是否是正确的数, 复杂度为O(n);class Solution {public: int firstMissingP

2016-04-21 23:13:49 213

转载 hiho 43 骨牌覆盖问题·三

问题http://hihocoder.com/contest/hiho43/problem/1代码程序递归查找状态转移矩阵。#include <bits/stdc++.h>using namespace std;enum {maxk = 7, max2k = 1<<maxk, mod=12357};int M[32][max2k][max2k];int d[max2k][max2k];in

2016-04-21 22:24:50 316

转载 hiho 42 骨牌覆盖问题·二

问题http://hihocoder.com/contest/hiho42/problem/1 3*n解法推到状态转移矩阵,然后转换为矩阵幂次。#include <bits/stdc++.h>using namespace std;int m[32][8][8];int d[8][8];const int mod= 12357;void mul(int C[8][8], int a[8]

2016-04-20 17:45:18 342

原创 hiho 41 骨牌覆盖问题·一

问题快速求得斐波拉切数列的某一位。解法首先将递推公式写成矩阵相乘的形式,然后计算出所有2的幂次的矩阵。对任意数,分解成2的幂次求得。 复杂度O(logn)#include <bits/stdc++.h>using namespace std;const int mod = 19999997;struct M{ long long a, b, c, d;};M m[32];M m

2016-04-20 16:20:19 293

转载 hiho 40 三分·三分求极值

问题描述对于一个凸函数。 http://hihocoder.com/contest/hiho40/problem/1解法先确定搜索范围,【-∞\infty, −b/2a-{b/2a}】 还是【−b/2a-{b/2a},+∞\infty】; 然后不断缩减区间直到结果符合要求。#include <bits/stdc++.h>using namespace std;double a, b, c,

2016-04-20 15:18:26 269

原创 hiho 39 二分·归并排序之逆序对

问题寻找逆序数 http://hihocoder.com/contest/hiho39/problem/1解法归并排序,复杂度o(nlogn)#include <bits/stdc++.h>using namespace std;enum {maxn = 100000+5};int a[maxn];int temp[maxn];int n;long long ret;void mer

2016-04-20 11:37:57 256

原创 hiho 38 二分·二分答案

问题http://hihocoder.com/contest/hiho38/problem/1解法二分搜索+bfs 如果换做dfs会超时。#include <bits/stdc++.h>using namespace std;enum {maxn = 10000+5};int n, m, k, t;vector<int> G[maxn];vector<int> len[maxn];in

2016-04-20 10:02:50 318

原创 hiho 37 二分查找k小数

问题http://hihocoder.com/contest/hiho37/problem/1解法二分求解。复杂度nlogn#include <bits/stdc++.h>using namespace std;int *a;int partition(int L, int R){ int pos = L; R++; for(;;){ do{++L;}

2016-04-19 22:31:49 225

转载 hiho 36 划分

快速排序的划分方式: 注意划分后等于key的值可能在左边也可能在右边。key也不一定在中间。int partion(int L, int R, int key){ --L; ++R; for(;;) { do{ L++;} while(a[L] < key); do{ R--;} while(a[R] > key);

2016-04-19 21:22:47 172

转载 hiho 35 二分图三·二分图最小点覆盖和最大独立集

二分图最小点覆盖 = 最大匹配数 最大独立集 = 顶点数- 最大匹配数

2016-04-19 19:36:03 209

原创 hiho 34 二分图二•二分图最大匹配之匈牙利算法

问题二分图的最大匹配算法解法寻找一条交错路径,路径中的边进行翻转。 优化:1, 只要计算一个集合中的顶点。 2, 在每个顶点处,记录已经查找过的另一集合的顶点,防止重复。#include <bits/stdc++.h>using namespace std;enum{maxn = 1000+5};vector<int> G[maxn];int color [maxn];int res[

2016-04-19 17:15:12 216

原创 hiho 32 二分图判定一

问题http://hihocoder.com/contest/hiho33/problem/1解法先找一个节点染成白色,将子节点染成黑色,做宽度优先搜索进行染色,如果发现两个节点有边链接,但是颜色相同就返回错误。当存在多个联通分量时,要多次选择节点。#include <bits/stdc++.h>using namespace std;enum {maxn = 10000+4};vector<

2016-04-19 15:14:31 231

原创 LeetCode 40. Combination Sum II

问题https://leetcode.com/problems/combination-sum-ii/解法回溯法,此题与39不同在于一个数可能出现了多次,此时我们需要制定规则。 首先对所有数从小到大排序,接着回溯法枚举选择和不选择每个数,对于相同数出现多次,我们规定只有第一个数被选择,之后的数才能被选择。 例如 111333444第一个1被选择第二,三个1才可以被选择。这样就不会出现重复。cla

2016-04-19 12:44:30 266

原创 LeetCode 39. Combination Sum

问题https://leetcode.com/problems/combination-sum/解法回溯法, 由于是要得到所有结果,如果使用dp求解,每一个状态都要存储可能到达自己的状态,内存开销太大。class Solution {public: void dfs(vector<vector<int>> &ret, vector<int>& now, vector<int>& cand,

2016-04-19 11:29:59 243

原创 LeetCode 38. Count and Say

问题https://leetcode.com/problems/count-and-say/解法模拟法, n=100都会超时。class Solution {public: string countAndSay(int n) { string ret; ret.push_back('1'); for (int i=2; i<=n; ++i){

2016-04-19 10:34:25 215

原创 LeetCode 37 SudoKu Solver

问题https://leetcode.com/problems/sudoku-solver/解法回溯,注意返回上一级之前要将状态恢复。class Solution {public: bool dfs(vector<vector<char>>& board) { int use[10]; memset(use, 0, sizeof(use));

2016-04-19 09:58:08 226

原创 LeetCode 35. Search Insert Position

问题https://leetcode.com/problems/search-insert-position/解法二分查找比大于等于target的第一个元素位置 首先R= nums.size() 表示R是比所有元素都大的。此时只要在[L, R-1]之间找到一个比target 大的最小位置。class Solution {public: int searchInsert(vector<in

2016-04-18 22:54:33 194

3D数学基础 图形与游戏开发

《3D数学基础 图形与游戏开发》 作为一本3D图形学入门书籍,其语言简练,生动易懂。主要内容包括EulerAngle, Quaternion, Matrix, 并给出了C++ 实现。注意在翻译版中代码是有一些错误的,不能直接使用, 建议大家自己推导一遍。 该版本是黑白扫描版,不是很清晰,且翻译版的部分公式和代码有错误,请大家注意。

2017-01-02

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除