Time of Update: 2018-12-05
並查集#include<iostream>using namespace std;#define N 30000#define G 501int p[N], group[N];int main(){ int n, g; while(scanf("%d %d", &n, &g) == 2) { if(n + g == 0) break; int i,j,k;
Time of Update: 2018-12-05
這是一道DP問題,覺得挺有意思的,所以時隔數日又寫了一遍……#include<iostream>#include<cstdio>using namespace std;int dp[20][20][20][20];int a[20];int main(){ int f,i,j,k; int t, cases; scanf("%d", &cases); t = 1; while(t <= cases) {
Time of Update: 2018-12-05
/*求圓(x1,y1,R)和圓(x2,y2,r)的交點數組p存放圓心(1~n-1)和交點(n~),數組radius存放半徑 count 用於記錄交點數(包括圓心的數目) */for(int i=0; i<n; i++){ // 初始化 double x1, y1, R; x1 = p[i].x, y1 = p[i].y,R = radius[i]; double x2, y2, r; x2 = p[j].x, y2 = p[j].y,r = radius[
Time of Update: 2018-12-05
Long Distance TaxiTime Limit: 30000ms, Special Time Limit:75000ms, Memory Limit:65536KBTotal submit users: 11, Accepted users: 7Problem 12523 : No special judgementProblem descriptionA taxi driver, Nakamura, was so delighted because he got a
Time of Update: 2018-12-05
進階網路流建圖啊!起初看這題,直接嚇尿了... 不會....思路看這裡......很不錯的分析啦。一點點二逼的錯誤,讓我找了好久!很久沒這麼二了!一個大於符號打反了.. 還有一個變數沒有初始化,我去!範例都讓我跑對了!CODE:#include<iostream>#include<string>#include<cmath>#include<algorithm>#define MN 222#define ME 1111#define FF(i,a,
Time of Update: 2018-12-05
查了很多資料,看了很多課件..這種NP難問題.. 確實什麼輕易的解法... 長路漫漫。直接求最大獨立集的方法能寫了,最大團怎麼求呢?另外吐槽一句:網上很多題解中都有最大獨立集=補圖的最大團。這沒錯。但是,很多都有一句下面是求最大團的代碼.. 我去.. 概念清楚了再來寫題解好麼.. 吐槽完畢.#include<iostream>using namespace std;int N,M;struct Edge{ int v,next;}E[111111];int
Time of Update: 2018-12-05
很久沒做線段樹的題目了。自己想想延遲標記怎麼弄...#include<iostream>#define MAXN 55555using namespace std;int tree[MAXN<<2];void pushUp( int rt ){ tree[rt]=tree[rt<<1]+tree[rt<<1|1];}void build( int l,int r,int rt ){ if( l==r ) { scanf(
Time of Update: 2018-12-05
2011/10/12--2011/10/17眨眼5天過去了,這幾Apsara Infrastructure Management
Time of Update: 2018-12-05
這也是一道比較簡單的圖論問題!可以使用Floyd演算法解決!呵呵……代碼好下:/*ID: guo geerPROG: butterLANG: C++*/#include<iostream>#include<cstring>#include<string>#include<fstream>using namespace std;#define MAXN 10000000int pas[1000];int dist[1000][1000];int
Time of Update: 2018-12-05
有太多不知道,又常常焦急地想去知道,因為這份心情,所以我願意將我會的與大家分享——這也是我建立這個部落格的目的!今天發現自己辛辛苦苦做出一個題目後,越來越懶得寫說明了。突然想起了自己當初建立這個部落格時,是抱著份什麼心情............hehe!這道真的很有意思!做了兩天!今天終於做出來了,真的很高興。。。。INPUT FORMATThe order of the input lines dictates the order of laying down the rectangles.
Time of Update: 2018-12-05
由於自己做代碼最佳化時,條件不清晰,兩個變數寫錯導致WA了兩次,不應該!#include<iostream>#include<cstdio>#define MAXN 222222using namespace std;int tree[MAXN<<2];int N,M;void pushUp( int rt ){ tree[rt]=max(tree[rt<<1],tree[rt<<1|1]);}void build( int
Time of Update: 2018-12-05
這題和八數位十分相似,或許是我的遺留問題吧....敲完總是不過,各種錯誤。遲遲下不了手的原因就在於對空間的把握問題。要節約空間就必須設計一個好的hash函數,不然時空開銷大。關鍵在於雜湊怎麼弄了?八位元--->87654321如果採用這麼大的空間,空間消耗太大,許多記憶體都沒採用,不行... 後來查了下資料,發現有康托展開恰好是結果全排列的雜湊問題。有了康托展開之後,全排列的問題就可以採用最小的空間消耗了,8!=40320<<87654321;這樣就可以用bfs了。當然8個數也
Time of Update: 2018-12-05
[雜湊函數]//1.第一種hash方法 typedef long long LL;const int HashMax = 1000003;LL Hash[HashMax];//y,w為需要雜湊的兩個值 int MakeHash(int y, int w){LL situ=(LL)y<<24|w;//定義雜湊策略 LL big=situ%HashMax;while( Hash[big]!=-1&&Hash[big]!=situ )big=(big<<1|1)
Time of Update: 2018-12-05
這道題真的很經典!首先我們只知道矩陣的最近一列,但我們容易得出矩陣的第一列——若有‘0’,剛應該全在第一列的前面。例如51 0 0 1 0 0 0 0 1 10 0 1 1 00 1 1 0 01 0 0 0 11 1 0 0 0 然後就是必須理解,假設第一列的三個‘0’是不同的,那麼在最後一列,他們的相對順序也是不變的,可以這樣理解,也就是將前三行分別右移一位,‘0’也就到最後一列了,但這三行的相對大小不小,呵呵。。。‘1’也是一樣的! 設first,
Time of Update: 2018-12-05
先貼一個TLE的代碼...#include<iostream>#include<cstdio>#define MAXN 11111using namespace std;int gt[MAXN<<2],st[MAXN<<2];int date[MAXN];void pushUpmax( int rt ){ gt[rt]=max(gt[rt<<1],gt[rt<<1|1]);}void pushUpmin( int rt )
Time of Update: 2018-12-05
歐拉迴路,採用遞迴的方法。採用遞迴的方法實現。/*ID:bysenLANG:C++PROG:fence*/#include<stdio.h>#include<stack>#define MAXN 501#define MAXF 1025using namespace std;int map[MAXN][MAXN]={0};int circuit[MAXF];int nodenum;int maxnode=0;int degree[MAXN]={0};int N;int
Time of Update: 2018-12-05
這道題目,以前寫過類似的。所以這次看了題目後,還是有頭緒的。不過這道真的很麻煩啊!用到了Hash + BFS1、2、3、4、5、6、7、8不管將它們怎樣變換,最多也就8! = 40320 種情況,所以可以使用BFS演算法枚舉下,打表即可。這是總的思想。但1……8是字串,不好打表,所以這時就用到了Hash演算法,我用的字串轉化演算法是從一位大牛那拷過來,挺好的。其它不需要解釋了!hehe....原始碼好下:/*ID: guo geerPROG: msquareLANG:
Time of Update: 2018-12-05
一點點想當然的想法使得我WA了6次...對線段樹的理解又深了一點。熟悉了加標記的操作。#include<iostream>#include<cstdio>#define MAXN 111111using namespace std;int tree[MAXN<<2];int flag[MAXN<<2];void PushUp( int rt ){
Time of Update: 2018-12-05
http://acm.hdu.edu.cn/showproblem.php?pid=3489NecklaceTime Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 320 Accepted Submission(s): 137Problem DescriptionHenryy gave the princess of the
Time of Update: 2018-12-05
2012長春網賽的題目,光頭了...悲劇.現在知道做了。分組為[a,b]區間內除k餘m的分為一組。這樣按組來更新就好了。這題的突破點就在於k很小。線段樹:#include<iostream>#include<cstdio>#include<cmath>#include<cstring>#define MN 50010using namespace std;int tree[MN<<2][55];int flag[MN<<2]