Time of Update: 2018-12-05
POJ-3259-Wormholeshttp://poj.org/problem?id=3259bellman_ford判斷是否有負環#include<iostream>#include<cstdio>#include<cstring>#include<cstdlib>using namespace std;#define MAX 0x7fffffffstruct edge{int x,y,v;}edge[6000];int m,n,w;int
Time of Update: 2018-12-05
POJ-2823-Sliding Windowhttp://poj.org/problem?id=2823求區間的最大值與最小值,線段樹即可,C++過了,G++逾時,囧#include<iostream>#include<cstring>#include<cstdio>#include<cstdlib>using namespace std;#define N 1000005struct cam{int x;int y;int min;int
Time of Update: 2018-12-05
POJ-2828-Buy Ticketshttp://poj.org/problem?id=2828線段樹,逆序插入#include<iostream>#include<cstdio>#include<cstring>#include<cstdlib>using namespace std;#define N 200010struct cam{int x,y;int num;}list[N*8];int pos[N],value[N],ans[N]
Time of Update: 2018-12-05
POJ-1204-Word Puzzleshttp://poj.org/problem?id=1204字典樹加深搜#include<iostream>#include<cstring>#include<cstdio>#include<cstdlib>using namespace std; char map[1005][1005];int n1,n2;int xx,yy;int dirx[8]={-1,-1,0,1,1,1,0,-1};int
Time of Update: 2018-12-05
POJ-1679-The Unique MSThttp://poj.org/problem?id=1679次小產生樹,prim稍作改變即可,每次加入新的頂點時,如果有不止一條權值最小的最短邊,則說明最小產生樹不只一種#include<iostream>#include<cstdio>#include<cstring>#include<cstdlib>using namespace std;#define N 105#define INF 99999
Time of Update: 2018-12-05
POJ-2728-Desert Kinghttp://poj.org/problem?id=2728有N個村莊,給出每個村莊的座標和海拔,,benifit為兩點之間的距離,cost為兩點的高度差,現在要求一棵樹使得 cost / benift 最小,即求一個最優比例產生樹第一次遇見這種產生樹,在網上找了個解法假設sigma(h)/sigma(l)==K 均值K可取,即:
Time of Update: 2018-12-05
POJ-1273-Drainage Ditcheshttp://poj.org/problem?id=1273基本的最大流,Ford-Fulkerson演算法,按LRJ的白書寫的#include<iostream>#include<cstring>#include<queue>using namespace std;#define INF 0x7fffffffint main(){int n,m;int from,to,w,f;int u,v;int cap[
Time of Update: 2018-12-05
POJ-2195-Going Homehttp://poj.org/problem?id=2195最小費用最大流,假想一個源點,一個匯點代碼模仿網上的寫的,還要再好好研究哇#include<stdio.h>#include<string.h>#include<math.h>#define maxn 300#define INF 0x7fffffffint min(int x,int y){return x<y?x:y;}struct node
Time of Update: 2018-12-05
POJ-1511-Invitation
Time of Update: 2018-12-05
#include <cstdio>#include <cstdlib>#include <cstring>#include <iostream>#define INPUTusing namespace std;/* Problem : HDU1272 - 小希的迷宮 State : 54213202012-02-26 23:40:14Accepted127262MS1636K3853 BG++c0de4fun
Time of Update: 2018-12-05
HDU-1247-Hats Wordshttp://acm.hdu.edu.cn/showproblem.php?pid=1247還是字典樹的題目,將每個單詞分成兩個單詞即可,尋找是否兩個單詞均在字典樹中注意建樹的時和之前略有區別,這題在插入單詞時,只需記錄單詞結尾的節點,不需要記錄一個單詞的所有首碼#include<iostream>#include<cstdio>#include<cstring>#include<cstdlib>using
Time of Update: 2018-12-05
HDU-2846-Repositoryhttp://acm.hdu.edu.cn/showproblem.php?pid=2846題意是給出一些模式串,再給出幾個詢問,詢問給出的字串在多少個模式串中出現比如字串abc所含的字串有a,ab,abc,b,bc,c可用字典樹解決,字典樹能很好的處理首碼出現的次數,所以可將模式串分解,依次插入需要注意的是對於同一個模式串的不同子串可能有相同的首碼,為了避免多次計算,可以添加字典樹節點的資訊,添加num記錄最後插入的字串是第num個模式串的子串#inclu
Time of Update: 2018-12-05
HDU-1251-統計難題http://acm.hdu.edu.cn/showproblem.php?pid=1251基本的字典樹,字典樹又稱單詞尋找樹,Trie樹,是一種樹形結構,是一種雜湊樹的變種。典型應用是用於統計,排序和儲存大量的字串(但不僅限於字串),所以經常被搜尋引擎系統用於文本詞頻統計。它的優點是:利用字串的公用首碼來節約儲存空間,最大限度地減少無謂的字串比較,查詢效率比雜湊表高。如所示,每一個紅色節點都一個單詞,白色節點表示公用首碼#include<iostream>
Time of Update: 2018-12-05
#include <iostream>#include <stdio.h>#include <memory.h>const int MAXSIZE = 10000;using namespace std;int trains[MAXSIZE];int orders[MAXSIZE];int stacks[MAXSIZE];int top;int main(){// freopen("b:\\acm\\input.txt","r",stdin);
Time of Update: 2018-12-05
POJ-3264-Balanced Lineuphttp://poj.org/problem?id=3264線段樹,求區間的最大值與最小值之差#include<stdio.h>#include<string.h>#include<stdlib.h>#define N 50005#define INF 0x7ffffffint num[N];struct cam{int x; //起點int y; //終點int min; //最小值int max;
Time of Update: 2018-12-05
#include <iostream>#include <stdio.h>//#define DBGusing namespace std;const int MAXSIZE = 10000;char map[MAXSIZE][MAXSIZE];int N,M;unsigned long LakeCounts;bool iFirstLake = true;bool iCounted = true;void dfs(int x,int y){ int m,n;
Time of Update: 2018-12-05
POJ-3468-A Simple Problem with Integershttp://poj.org/problem?id=3468成段更新線段樹#include<stdio.h>#include<string.h>#include<stdlib.h>#define N 100005int num[N];struct cam{int x; //起點int y; //終點__int64 sum; //和int add;
Time of Update: 2018-12-05
題目地址:http://acm.hdu.edu.cn/showproblem.php?pid=2717這點需要特別注意的是HDU特別坑爹,POJ上是單組資料,多點測試,HDU是一點測試,多組資料!所以在POJ上把while(cin >> N >> K)去掉也是AC的,簡單的BFS#include <iostream>#include <stdio.h>#include <queue>#include
Time of Update: 2018-12-05
POJ-2528-Mayor's postershttp://poj.org/problem?id=2528線段樹的離散化,離散化就相當於是先做映射,然後再建樹對於題目給出的測試資料1 42 68 103 47 10將端點取出並且排序,去掉相同的座標,即1,2,3,4,6,7,8,10,那麼1,2,3,4,6,7,8,10可以離散化為1,,2,3,4,5,6,7,8 題目給出的區間可以表示為1 42 57 83 46
Time of Update: 2018-12-05
#include <iostream>#include <stdlib.h>#include <stdio.h>/* Reference:http://www.cnblogs.com/youngxiao/archive/2010/05/19/1739381.html.THX A LOT TO YOU. author:YuXun Lu(A.K.A Kyle Broflovlaski) problem:poj2796 Begin Time: