【樹狀數組】hdu 2852

對點的操作,最好就用樹狀數組!#include <vector>#include <list>//#include <map>#include <set>#include <queue>#include <string>#include <deque>#include <stack>#include <algorithm>#include <iostream>#include

【線段樹+歸併排序】poj 2104

本題是利用了歸併排序的過程,其實歸併樹就是線段樹+歸併,只是線段樹每個區間裡存了這個區間裡的有序序列,注意rank的求法,二分答案,求出每個中間值mid在原始序列區間[s,t]裡的rank,其中這裡面又可以用二分來求mid在[s,t]裡排第幾,最後相加就是這個rank,比較蛋疼的就是二分時的位置問題,什麼時候+1,什麼時候-1,很難搞!每次詢問的複雜度O(lgn*lgn*lgn),所以總共為O(m*lgn*lgn*lgn)ps:歸併樹原理: 如果對於一段區間,僅尋找一次第k大元素的話好說,直接一

【迴文串】ural 1297

迴文串,原理:由一點向兩邊延伸,注意不要超出數組範圍!聽說可以用尾碼數組,不懂,有空再研究研究#include <vector>#include <list>#include <map>#include <set>#include <queue>#include <string.h>#include <deque>#include <stack>#include

【叉乘判相交】

常用叉乘來判斷兩線段或兩直線是否相交。假設a和b是兩個向量, 那麼它們的叉積c=aXb可如下嚴格定義。 |c|=|a×b|=|a||b|sin<a,b>,那麼我們可以利用sin<a,b>的正負來判斷B線段一端點在A線段的左還是右,注意:判斷線段相交要利用4個端點做叉乘,若 P × Q > 0 , 則P在Q的順時針方向。若 P × Q < 0 , 則P在Q的逆時針方向。若 P × Q = 0 , 則P與Q共線,但可能同向也可能反向bool f(int

hdu 阿里巴巴網路賽 hdu 3951 3952 3953 3959

暫貼4條水題,其餘的研究中。。。3951#include <vector>#include <list>#include <map>#include <set>#include <queue>#include <string.h>#include <deque>#include <stack>#include <bitset>#include

【高精度運算】

雖說高精度直接考查的越來越少,不過還是以防萬一。#define maxlen 1000struct bint{    int len,s[maxlen];    bint(){len=1;memset(s,0,sizeof(s));}    //*******本模板既可輸入字串,也可輸入整數*******//    bint(int t){    memset(s,0,sizeof(s));len=1;    while(t){s[len++]=t%10;t/=10;}  

【隨機演算法】poj 3318

題目明說不能用一般O(n^3)方法,所以要尋求出路!首先,我們要知道矩陣連乘運算公式x*a*b=x*c,這樣就好辦,令x為1 x n矩陣,左邊算出未一階,右邊也是一階,把複雜度降為O(n^2),對於x我們可以用隨機函數賦值,也可以不用,直接令x[i]=i。注意隨機函數用法srand((unsigned int)time(0))——種子只要產生一次!記得加標頭檔<time.h>!#include <vector>#include <list>#include &

zoj 1733【最長公用子序列DP】

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1733關鍵:狀態方程 if(c1[i]==c2[j]) dp[i][j]=dp[i-1][j-1]+1;else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);#include <vector>#include <list>#include <map>#include <set>#include

【單位圓覆蓋最多點】POJ 1981

經典幾何體,求單位圓最多覆蓋點數。這裡用O(n^3)演算法,聞說有O(n^2*logn),但不會搞。方法:枚舉任意兩點,以此為弦做新圓,(ps:不能以弦中心做圓,因為這圓不是最大的)接著就枚舉所有點,求出最大值。#include <list>#include <map>#include <set>#include <queue>#include <string>#include <deque>#include

zoj 2297【DP+位元運算狀態壓縮】

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2297越來越覺得位元運算好神啊。。。用位元運算來儲存每個狀態#include <vector>#include <list>#include <map>#include <set>#include <string.h>#include <deque>#include

【字串暴力】hdu 2847

暴力不解釋。#include <vector>#include <list>#include <map>#include <set>#include <queue>#include <string>#include <deque>#include <stack>#include <algorithm>#include <iostream>#include

【DP】ZOJ 2068

DP:dp[i][j]表示a前i個,b前j個最小的badness方程:dp[i][j]=min( dp[i-1][j-1]+(a-b)*(a-b), dp[i-1][j], dp[i][j-1]),注意從a中取的筷子數=b中取的筷子數!code:#include <vector>#include <list>#include <map>#include <set>#include <queue>#include

【隨機演算法】poj 2576/zoj 1880

這題可用DP做,可是本人太菜,不懂,只會投機取巧^_^,所以用隨機來AC,的確有點隨機,個人覺關鍵是找准隨機次數,例如這題,隨機迴圈5w次剛好,這就難免貢獻幾次wa咯~POJ 47MS / ZOJ 10MS。。。不錯不錯#include <vector>#include <list>#include <map>#include <set>#include <queue>#include <string.h>#include

【樹狀數組】hdu 4000

給出一個1~N的序列,問有多少組x<z<y方法:樹狀數組,先求出xyz+xzy的個數,很簡單,算出比ai大的個數,比ai小的個數,這個用樹狀數組實現,開始想的時候是倒過來建樹的,即下標n~1順序,發現沒必要,順序也可以,求出比ai小的個數p,然後草稿紙算算,算出比ai大的個數是(n-i-a[i]+p){求這個式子過程:比ai小的個數是p,按理來說有ai-1個比ai小的數,那麼肯定有ai-1-p個比ai小的在ai右面,佔據了ai-1-p個位置,然後ai右面剩下n-(i+1)個空位,所以

【類比退火】POJ 2420/ZOJ 1901 費馬點

n 邊形的費馬點, 即某一點到n 邊形的n

【STL中的erase()方法 】

 STL中的容器按儲存方式分為兩類,一類是按以數組形式儲存的容器(如:vector 、deque);另一類是以不連續的節點形式儲存的容器(如:list、set、map)。在STL中用earse()方法刪除一個元素很簡單,基本上也不會出什麼錯,但是在遍曆刪除某條件下的元素時就有可能會弄錯了。在list、set、map、vector和deque遍曆刪除某條件元素時通用的一種方法可以這樣使用: std::list< int> List; //

【類比退火】最小球POJ 2069/codeforces 82 E

這兩題都是大同小異,一個求最小球半徑,一個求球心。方法都是用類比退火,每次往最遠距離移動,並且調整步距,計數器要取值適當,掌握不好火候就會悲劇~下面貼poj2069,codeforces 82E差不多,改一下輸入輸出就過#include <vector>#include <list>#include <map>#include <set>#include <queue>#include <string.h>#include

【位元運算+暴力】Codeforces Beta Round #86 (Div. 2 Only) B

本想用圖染色的,後來研究了一下才知道這個想法很傻很天真,因為Welch Powell 演算法只能求出最小用幾種色,不能求出最大有哪幾個共存點!還有,再一次被for裡面的i坑了,i裡有i,結果查了半天才知道這個詭異的傢伙複雜度:O((1<<n)*n^2),最壞也是65536*256=16777216,2s肯定可以跑完,而且cf的伺服器很強大#include <map>#include <set>#include <list>#include <

【二分】hdu 4022

SB的二分,O(nlgn),其實比賽時已經這樣想過,不過還是懶得去敲 #include <map>#include <set>#include <list>#include <queue>#include <deque>#include <stack>#include <string>#include <time.h>#include <cstdio>#include

【tarjan縮點】hdu 3072

這題要先縮點在找沒有入邊的點,再找權值最小的邊,注意:可能有重邊,看sample3就知道!用vector和stack的緣故,比較慢500+ms#include <list>#include <map>#include <set>#include <queue>#include <string>#include <deque>#include <stack>#include

總頁數: 61357 1 .... 13152 13153 13154 13155 13156 .... 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.