uva 10154

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&

uva 10986

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--)

leetcode – 3 Sum

題目來源:http://www.leetcode.com/onlinejudge解題報告:簡單的用遞迴實現的,有一點是注意數組中可能會有重複數字,所以要考慮結果中不要輸出重複結果。#include <iostream>#include <algorithm>#include <vector>using namespace std;class Solution {public: void f(int index, vector<int>

演算法導論學習筆記-第二章-演算法入門

第二章-演算法入門 總結:這一章講了插入排序及其演算法分析,迴圈不變式的證明,合并排序(分治法)及其演算法分析。 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)        

uva 10791

還算比較水的一個數學題 求因子的最小和  總是用小的數去除   注意特判  是用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

leetcode – 3 sum closest

題目來源: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))

SGU 180

求逆序數對    歸併排序  #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

O(n)演算法求最長迴文子串

轉自:http://www.cnblogs.com/wuyiqi/archive/2012/06/25/2561063.html 首先:大家都知道什麼叫迴文串吧,這個演算法要解決的就是一個字串中最長的迴文子串有多長。這個演算法可以在O(n)的時間複雜度內既線性時間複雜度的情況下,求出以每個字元為中心的最長迴文有多長,  

相交圓面積

求兩個圓相交部分的面積#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)*(

uva 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 n; while(scanf("%d"

uva 624

背包問題  總時間為容量,單個唱片時間為各個物體的價值與體積   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,

一道簡單的面試題

網上搜的面經,有一道題,是這樣的:原有一個有序數組,分成前後兩部分,然後將這兩部分交換得到一個新的數組。寫一個函數,參數是這個新的數組,要求找到數組分開的那個結點,而且要考慮時間複雜度。 首先,由於數組原來是有序的,在這裡假設為升序,那麼即使兩部分交換了後,兩部分的資料仍然是升序的,設原來數組是前部分+後部分,交換後數組變成後部分+前部分,但是後部分的數的最小值仍然比前部分的最大值要大,因此,後部分的資料一定比前部分的資料大。 可以通過一次遍曆數組的方式,找到分開的節點,如果資料一直升序下去,就

uva 3952

因為一個小錯 不過  好不爽........#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

uva 10827

與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);

演算法導論學習筆記-第七章-快速排序

第七章 快速排序 總結:這章講了快速排序的演算法,分析了演算法複雜性,又講了快速排序的隨機版 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

uva 10534

一開始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 ==

uva 558 Bellman_Ford

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;

POJ 1321-棋盤問題 簡單搜尋DFS

題目來源: http://acm.pku.edu.cn/JudgeOnline/problem?id=1321 解題報告: 棋盤問題, 棋子擺放的位置只能是#, 且不能同行和同列. 由於我採用的是按行遞增的順序來搜尋的, 因此不可能出現同行的情況, 對於同列的情況, 我設定了一個變數col[], 來儲存列的訪問狀態, 對於之前訪問過的列, 棋子是不能再放在這一列上的.  dfs(begin, num) 代表將第k-num棵棋子放在begin行上,

interviewstreet – Grid Walking 動態規劃

題目來源: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,

poj 2182 Lost Cows(樹狀數組)

題目連結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

總頁數: 61357 1 .... 15146 15147 15148 15149 15150 .... 61357 Go to: 前往

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.