Time of Update: 2018-12-05
dp 記憶化搜尋 做的時候像dfs #include <iostream>#include <cstring>#include <cstdio>#include <algorithm>using namespace std;struct tur{ int x,y,s;} tur[6000];int d[6000] = {},n;int flag[6000] = {};int _max;int dp(int i){ int&
Time of Update: 2018-12-05
ford 逾時 使用優先隊列的Dijkstra 演算法//#include <cstdio>//#include <cstring>//#include <algorithm>//#define INF 500000000//using namespace std;//int a[20010][20010];//int main()//{// int t, ca = 1;// scanf("%d",&t);// while(t--)
Time of Update: 2018-12-05
題目來源:http://www.leetcode.com/onlinejudge解題報告:簡單的用遞迴實現的,有一點是注意數組中可能會有重複數字,所以要考慮結果中不要輸出重複結果。#include <iostream>#include <algorithm>#include <vector>using namespace std;class Solution {public: void f(int index, vector<int>
Time of Update: 2018-12-05
第二章-演算法入門 總結:這一章講了插入排序及其演算法分析,迴圈不變式的證明,合并排序(分治法)及其演算法分析。 1. 插入排序類似於撲克牌的插入過程,設A[1...j-1]是排好序的一個數組,將A[j]插入A[1...j-1]中使A[j]稱為排好序的一個數組,j <- 2 to length[A] 演算法分析:最好情況,整個數組已經是順序的了,O(n) 最壞情況,整個數組是逆序的,O(n^2) 平均情況,O(n^2)
Time of Update: 2018-12-05
還算比較水的一個數學題 求因子的最小和 總是用小的數去除 注意特判 是用int不行哦........#include <cstdio>#include <cmath>int main(){ long n, ca = 1; while(scanf("%ld",&n) == 1 && n) { long k = n; long ans = 0, flag = 0; for(int
Time of Update: 2018-12-05
題目來源:http://www.leetcode.com/onlinejudge解題報告:思路與上題相似class Solution {public: int min; void f(int index, int size, vector<int> &num, int sum, int target) { if (size == 3) { if (abs(min) > abs(sum- target))
Time of Update: 2018-12-05
求逆序數對 歸併排序 #include <cstdio>#include <cstring>#include <cmath>#include <algorithm>using namespace std;int a[71010], b[71010];long long cnt;void merge_sort(int *A, int x, int y, int *T){ if(y-x > 1) { int m
Time of Update: 2018-12-05
轉自:http://www.cnblogs.com/wuyiqi/archive/2012/06/25/2561063.html 首先:大家都知道什麼叫迴文串吧,這個演算法要解決的就是一個字串中最長的迴文子串有多長。這個演算法可以在O(n)的時間複雜度內既線性時間複雜度的情況下,求出以每個字元為中心的最長迴文有多長,
Time of Update: 2018-12-05
求兩個圓相交部分的面積#include <cstdio>#include <cstring>#include <cmath>#define pi acos(-1.0)struct node{ double x; double y; double r;} c[2];double area(int i, double r1, int j, double r2){ double d= sqrt((c[i].x-c[j].x)*(
Time of Update: 2018-12-05
降維 枚舉行累加 然後求單行上最大連續和#include <iostream>#include <cstring>#include <cstdio>#include <cmath>#include <algorithm>#define maxn 110using namespace std;int a[maxn][maxn];int b[maxn];int main(){ int n; while(scanf("%d"
Time of Update: 2018-12-05
背包問題 總時間為容量,單個唱片時間為各個物體的價值與體積 f【】 用來記錄路徑#include <cstdio>#include <cstring>#define M 10005int a[25],d[M],f[25][M];int main(){ int V; while(scanf("%d",&V) == 1) { int n; memset(d,0,sizeof(d)); memset(f,
Time of Update: 2018-12-05
網上搜的面經,有一道題,是這樣的:原有一個有序數組,分成前後兩部分,然後將這兩部分交換得到一個新的數組。寫一個函數,參數是這個新的數組,要求找到數組分開的那個結點,而且要考慮時間複雜度。 首先,由於數組原來是有序的,在這裡假設為升序,那麼即使兩部分交換了後,兩部分的資料仍然是升序的,設原來數組是前部分+後部分,交換後數組變成後部分+前部分,但是後部分的數的最小值仍然比前部分的最大值要大,因此,後部分的資料一定比前部分的資料大。 可以通過一次遍曆數組的方式,找到分開的節點,如果資料一直升序下去,就
Time of Update: 2018-12-05
因為一個小錯 不過 好不爽........#include <iostream>#include <fstream>using namespace std;struct Node{ int x, y;};class shap{public: int num; Node dian[22];} q[22];double getk(int x1, int y1, int x2, int y2){ return
Time of Update: 2018-12-05
與108類似 多加了兩層迴圈 水過#include <iostream>#include <cstring>#include <cstdio>#include <cmath>#include <algorithm>#define maxn 110using namespace std;int a[maxn][maxn];int b[maxn];int main(){ int t; scanf("%d",&t);
Time of Update: 2018-12-05
第七章 快速排序 總結:這章講了快速排序的演算法,分析了演算法複雜性,又講了快速排序的隨機版 1. 快速排序PARTITION(A, p, r)將A[p…r]進行就地重排,返回q,其中A[p…q-1]中的元素都小於A[q],A[q+1,…r]中的元素都大於A[q]。QUICKSORT(A, p, r)遞迴排序分析:最壞情況O(n^2) 最好情況O(nlgn) 平均情況O(n^2) 虛擬碼PARTITION (A, p, r)x <- A[r]i
Time of Update: 2018-12-05
一開始WA了 參考了一下 求正反兩個方向的最長上升子序列 並分別記錄在兩個數組中 最後求最大值#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int a[10010],c1[10010],c2[10010],d[10010];int cc(int n, int& i){ if(i ==
Time of Update: 2018-12-05
Bellman_Ford演算法 求圖中是否存在負權值的迴路 若圖中不存在 則最短路最多經過n-1個結點 若經過超過n-1個節點 則存在負權值的迴路 此圖永遠無法找到最短路#include<cstdio>#include<cstring>#include<queue>#include<vector>using namespace std;const int INF = 100000000;const int maxn = 1005;
Time of Update: 2018-12-05
題目來源: http://acm.pku.edu.cn/JudgeOnline/problem?id=1321 解題報告: 棋盤問題, 棋子擺放的位置只能是#, 且不能同行和同列. 由於我採用的是按行遞增的順序來搜尋的, 因此不可能出現同行的情況, 對於同列的情況, 我設定了一個變數col[], 來儲存列的訪問狀態, 對於之前訪問過的列, 棋子是不能再放在這一列上的. dfs(begin, num) 代表將第k-num棵棋子放在begin行上,
Time of Update: 2018-12-05
題目來源:https://www.interviewstreet.com/challenges/dashboard/#problem/4e48bfab1bc3e解題報告:首先計算群組合值C[m][n],按照公式C[m][n] = C[m-1][n-1] + C[m-1][n]獲得。f[i][j][k],代表第i維,位於位置j時,走k步有幾種走法。則有方程f[i][j][k] = f[i][j-1][k-1] + f[i][j+1][k-1],考慮j-1<=0,
Time of Update: 2018-12-05
題目連結DescriptionN (2 <= N <= 8,000) cows have unique brands in the range 1..N. In a spectacular display of poor judgment, they visited the neighborhood 'watering hole' and drank a few too many beers before dinner. When it was time to line up