C++
DamianGao
两句三年得,一吟双泪流。文章千古事,得失寸心知。
展开
-
Dijkstra算法
Dijkstra算法函数实现template<class EdgeType> void Dijkstra(AdjGraph<EdgeType> &G, int s, EdgeType D[], int Path[])//参数:G图引用,原创 2016-12-16 18:35:57 · 420 阅读 · 0 评论 -
Floyd算法
函数实现template<class EdgeType> void Floyd(AdjGraph<EdgeType> &G, EdgeType Adj[][3], int Path[][3]) //参数:图, //adj顶点编号不大于的最短路径长度, //path顶点编号不大于的最短路径中vj的前驱顶点编号 { int i, j, v;//i,j是计数器,v记录相应的顶点 int n原创 2016-12-16 21:02:17 · 301 阅读 · 0 评论 -
leetcode 7. Reverse Integer
class Solution { public: int reverse(int x) { long y=0; while(x != 0){ y = y*10+x%10; x /= 10; } if(y>INT_MAX||y<INT_MIN) ...原创 2018-03-06 10:54:46 · 92 阅读 · 0 评论 -
leetcode 13. Roman to Integer
class Solution { public: int romanToInt(string s) { int result=0; while(s.length()>0){ switch (s[0]){ case 'C': if(s[1]=='D'){ ...原创 2018-03-06 10:56:37 · 94 阅读 · 0 评论 -
leetcode 14. Longest Common Prefix
本渣的写法19ms class Solution { public: string longestCommonPrefix(vector<string>& strs) { int size = strs.size(); if(size==0) return ""; string result= s...原创 2018-03-06 17:31:13 · 107 阅读 · 0 评论 -
从数组中选出三条边,组成周长最大三角形
挑战程序设计竞赛(第2版)1.6.1题 O(nlogn)的算法 int n, a[MAX_N]; void solve(){ int ans = 0; sort(a,a+n-1); for(int i=n-3;i>=0;i--){ if(a[i]+a[i+1]>a[i+2]){ ans = a[i]+a[i+1]...原创 2018-04-14 09:42:23 · 3314 阅读 · 0 评论