锘??xml version="1.0" encoding="utf-8" standalone="yes"?>婷婷久久久亚洲欧洲日产国码AV,97r久久精品国产99国产精,青青草国产97免久久费观看 http://www.shnenglu.com/zoyi-zhang/category/6628.html縐嶇摐寰楃摐~~~縐嶈眴寰楄眴 zh-cn Sat, 11 Oct 2008 20:59:51 GMT Sat, 11 Oct 2008 20:59:51 GMT 60 pku 3110 璐績 http://www.shnenglu.com/zoyi-zhang/archive/2008/10/10/63703.htmlzoyi zoyi Fri, 10 Oct 2008 14:26:00 GMT http://www.shnenglu.com/zoyi-zhang/archive/2008/10/10/63703.html http://www.shnenglu.com/zoyi-zhang/comments/63703.html http://www.shnenglu.com/zoyi-zhang/archive/2008/10/10/63703.html#Feedback 0 http://www.shnenglu.com/zoyi-zhang/comments/commentRss/63703.html http://www.shnenglu.com/zoyi-zhang/services/trackbacks/63703.html n鐨勮寖鍥存槸50000錛屼粠澶у埌灝忚繘琛屾灇涓撅紝濡傛灉鏄冭瘯鐨勪竴澶╄繘鍫嗭紝涓嶆槸鍒欐壘鍑烘渶澶х殑閭d釜澶嶄範鏃墮棿涓婇檺 姣旇緝闅懼鐞嗙殑鏄椂闂磋漿鍖栭棶棰橈紝鎴戝湪榪欓噷鏄妸瀹冩彁鍓嶄簡31銆?銆?600浣滀負涓涓搗濮嬫椂闂達紝鐒跺悗閮藉仛涓涓漿鎹?br> 絎竴涓▼搴忔垜鏄啓浜嗕竴涓猟ate鐨勭被錛岄噸杞戒簡鍚勭鎿嶄綔錛岀幇鍦ㄤ篃瑙夊緱鍦ㄨ繖縐嶆瘮璧涙彁閲岄潰濡傛灉娌℃湁蹇呰榪樻槸灝戜簺綾繪瘮杈冨ソ錛屽お澶嶆潅浜嗭紝璋冭瘯璧鋒潵涔熶笉娓呮櫚 浠ヤ笅鏄痑c浠g爜錛?br>
#include < iostream > #include< algorithm > #define maxn 50005 int T[] = { 0 , 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 }; using namespace std; struct node { int test,bg,i; friend bool operator < (node a,node b) { return a.test > b.test; } } in [maxn]; int n; bool cmp2( int x, int y) { return in [x].bg < in [y].bg; } int leap( int y) { if ((y % 4 == 0 && y % 100 ) || (y % 400 == 0 )) return 1 ; return 0 ; } int DtoI( int d, int m, int y) { int yy,mm,ret = 0 ; for (yy = 1600 ;yy < y;yy ++ ) ret += 365 + leap(yy); for (mm = 1 ;mm < m;mm ++ ) ret += T[mm] + ( int )(leap(y) && mm == 2 ); ret += d; return ret; } void print( int x) { int yy,mm,dd; for (yy = 1600 ;x >= 365 + leap(yy);yy ++ ) { x -= 365 + leap(yy); if ( ! x) { printf( " 31.12.%04d\n " ,yy); return ; } } for (mm = 1 ;x >= T[mm] + ( int )(leap(yy) && mm == 2 );mm ++ ) { x -= T[mm] + ( int )(leap(yy) && mm == 2 ); if (x == 0 ) { printf( " %02d.%02d.%04d\n " ,T[mm] + ( int )(leap(yy) && mm == 2 ),mm,yy); return ; } } printf( " %02d.%02d.%04d\n " ,x,mm,yy); } int main() { // freopen("1","r",stdin); scanf( " %d " , & n); int i; for (i = 0 ;i < n;i ++ ) { char str[ 12 ]; scanf( " %s " ,str); int d,m,y,t; scanf( " %d.%d.%d " , & d, & m, & y); scanf( " %d " , & t); in [i].test = DtoI(d,m,y); in [i].bg = in [i].test - t; } sort( in , in + n); int maxd = in [ 0 ].test,index =- 1 ; int heap[maxn],heapsize = 0 ; bool yes = true ; int tmp = n; for (;yes && tmp;maxd -- ) { if (maxd == in [index + 1 ].test) { heap[heapsize ++ ] = index + 1 ; push_heap(heap,heap + heapsize,cmp2); ++ index; continue ; } if (heapsize > 0 ) { int top = heap[ 0 ]; pop_heap(heap,heap + heapsize,cmp2); heapsize -- ; if ( in [top].bg > maxd)yes = false ; else tmp -- ; } } if ( ! yes) printf( " Impossible\n " ); else { print(maxd+ 1 ); } return 0 ; }
]]>pku 2761 http://www.shnenglu.com/zoyi-zhang/archive/2008/07/15/56182.htmlzoyi zoyi Tue, 15 Jul 2008 05:46:00 GMT http://www.shnenglu.com/zoyi-zhang/archive/2008/07/15/56182.html http://www.shnenglu.com/zoyi-zhang/comments/56182.html http://www.shnenglu.com/zoyi-zhang/archive/2008/07/15/56182.html#Feedback 0 http://www.shnenglu.com/zoyi-zhang/comments/commentRss/56182.html http://www.shnenglu.com/zoyi-zhang/services/trackbacks/56182.html 鎴戜笉鏄庣櫧銆傘備負浠涔堜竴鐩撮敊銆傘傘傛垜鐜板湪榪樻槸涓嶆槑鐧姐傘?br>榪欐槸鎴戝啓榪欑被闂銆傘備技涔庨兘浼氬嚭鐜扮殑闂銆傘傝鎶婃暟緇勫紑鍗曞緢澶氬緢澶氬嶃傘傛垜鍒扮幇鍦ㄨ繕鏄笉鏄庣櫧榪欐槸涓轟粈涔?br> 榪樻槸絎竴嬈¤兘鍦ㄧ涓欏電殑鍛€傘傚懙鍛點傘傚皬瀹夋叞涓涓?br>
#include < iostream > #include< algorithm > #define MaxN 300005 #define MaxM 200005 using namespace std;int N,M,res[MaxM]; struct node { int pri,n; friend bool operator < (node a,node b) { return a.pri < b.pri; } }index[MaxN],ii[MaxN]; struct line { int b,e,k,n,ans; friend bool operator < (line a,line b) { return a.b < b.b; } }Line[MaxM]; int cc[MaxN]; void inser_del( int key, int flag) { int L = 0 ,R = N - 1 , mid ,v = 1 ; while (L < R) { cc[v] += flag; mid = (L + R) / 2 ; v *= 2 ; if (key <= mid ) R = mid ; else { v++ ; L = mid + 1 ; } } cc[v] += flag; } int solve( int k) { int L = 0 ,R = N - 1 , mid ,v = 1 ; while (L < R) { mid = (L + R) / 2 ; if (cc[ 2 * v] >= k) { R = mid ; v *= 2 ; } else { L = mid + 1 ; k -= cc[ 2 * v]; v = 2 * v + 1 ; } } return index[L].pri; } int main() { int i,j; scanf( " %d%d " , & N, & M); for (i = 0 ;i < N;index[i].n = i ++ ) scanf( " %d " , & index[i].pri); for (i = 0 ;i < M;Line[i].n = i ++ ) { scanf( " %d%d%d " , & Line[i].b, & Line[i].e, & Line[i].k); if (Line[i].b > Line[i].e)swap(Line[i].b,Line[i].e); -- Line[i].b; -- Line[i].e; } // 鍒濆鍖?/span>--> cc涓? sort(index,index + N); sort(Line,Line + M); for (i = 0 ;i < N;i ++ ) { ii[index[i].n].pri = index[i].pri; ii[index[i].n].n = i; } for (i = Line[ 0 ].b;i <= Line[ 0 ].e;i ++ ) inser_del(ii[i].n, 1 ); for (i = 1 ;i < M;i ++ ) { Line[i - 1 ].ans = solve(Line[i - 1 ].k); if (Line[i - 1 ].e >= Line[i].b) { for (j = Line[i - 1 ].b; j < Line[i].b; j ++ ) inser_del(ii[j].n, - 1 ); for (j = Line[i - 1 ].e + 1 ; j <= Line[i].e; j ++ ) inser_del(ii[j].n, 1 ); } else { for (j = Line[i - 1 ].b;j <= Line[i - 1 ].e;j ++ ) inser_del(ii[j].n, - 1 ); for (j = Line[i].b; j <= Line[i].e; j ++ ) inser_del(ii[j].n, 1 ); } } Line[i - 1 ].ans = solve(Line[i - 1 ].k); for (i = 0 ;i < M;i ++ ) res[Line[i].n] = Line[i].ans; for (i = 0 ;i < M;i ++ ) printf( " %d\n " ,res[i]); return 0 ; }
]]> 鍔ㄦ佺粺璁$殑闈欐佸疄鐜幫紙鏉庣澘錛?/title> http://www.shnenglu.com/zoyi-zhang/archive/2008/07/13/56041.htmlzoyi zoyi Sun, 13 Jul 2008 11:40:00 GMT http://www.shnenglu.com/zoyi-zhang/archive/2008/07/13/56041.html http://www.shnenglu.com/zoyi-zhang/comments/56041.html http://www.shnenglu.com/zoyi-zhang/archive/2008/07/13/56041.html#Feedback 0 http://www.shnenglu.com/zoyi-zhang/comments/commentRss/56041.html http://www.shnenglu.com/zoyi-zhang/services/trackbacks/56041.html 涓緇存儏鍐碉細
璁懼簭鍒楃殑鍏冪礌瀛樺偍鍦╝[]涓紝a鐨勪笅鏍囨槸1..n鐨勬鏁存暟錛岄渶瑕佸姩鎬佸湴鏇存柊鏌愪釜a[x]鐨勫鹼紝鍚屾椂瑕佹眰鍑篴[x1]鍒癮[y1]榪欎竴孌墊墍鏈夊厓绱犵殑鍜屻?
濡傛灉瑕佸姩鎬佹洿鏂癿嬈°傘傛垜浠樉鐒跺彲浠ョ敤o(mn)鐨勬毚鍔涘紕鍑烘潵 鍏跺疄鍙互o(mlogn)鐨勶紱 鍦ㄦ潕鐫跨殑璁烘枃閲屾彁鍑轟簡涓縐嶆柊鐨勬暟鎹粨鏋勶細 寰堝閥濡欙紝寰堝己澶э細 瀵逛簬搴忓垪a[]錛屾垜浠涓涓暟緇凜錛屽叾涓?v:shapetype id=_x0000_t75 stroked="f" filled="f" path="m@4@5l@4@11@9@11@9@5xe" o:preferrelative="t" o:spt="75" coordsize="21600,21600"> 錛坘涓篿鍦ㄤ簩榪涘埗涓嬫湯灝?鐨勪釜鏁幫級銆?br>c[i]=a[i]+a[i-1]+...+ a[i-2^k+1]//榪欎竴欏圭殑鏈鍚庝竴浣嶄竴瀹氭槸0 鍖呭惈a[x]鐨刢搴忓垪錛?/span>
c[x]=a[x]+a[x-1]+...+a[x-2^k+1] c[x+2^k]=a[x+2^k]+a[x+2^k-1]...+a[x]+...+a[x-2^k+1] .... 涓鐩村姞鍒?lt;=S鐨勭姸鍐?/span> 閽堝榪欎釜鎯呭喌銆傘傛垜浠湁涓や釜瀹炵幇銆傘備竴涓槸update(),鍙︿竴涓槸緇熻鐨勬搷浣?br>濡傛灉閽堝涓婇潰鐨勭粺璁″氨鏄眰緇欏畾鍖洪棿鐨剆um 錛坸,y錛?sum(1,y)-sum(1,x)錛?br>
procedure UPDATA(x,A) begin p←x while (p <= n) do begin C[p]←C[p]+ A p←p + LOWBIT(p) end end
姹俛[ 1 ] - a[x]鐨勫拰 function SUM(x) begin ans ← 0 p ← xwhile (p > 0 ) do begin ans←ans+ C[p] p←p - LOWBIT(p) end return ansend
鎴戜滑閫氳繃涓緇寸殑鍙互鎵╁睍鎴愪簩緇寸殑錛氾紙IOI MOBILES 錛?br>浠ヤ笅鏄垜鐨勮繖浠g爜錛?br>
#include< iostream > #define MaxS 1025 #define L(a) (a& (a ^ (a - 1 ))) int S,x,y,A,L,B,R,T; int c[MaxS][MaxS]; void update() { // x <= i < S鐨刢[i][y]鏇存柊 int i,j; for (i = x;i <= S;i += L(i)) for (j = y;j <= S;j += L(j)) c[i][j] += A; } int compute( int x, int y) { int result = 0 ,i,j; for (i = x;i > 0 ;i -= L(i)) for (j = y;j > 0 ;j -= L(j)) result += c[i][j]; return result; } int main() { int oper,ans; while (scanf( " %d " , & oper) && oper! = 3 ) { switch (oper) { case 0 : scanf( " %d " , & S); memset(c, 0 ,sizeof(c)); break; case 1 : scanf( " %d%d%d " , & x, & y, & A); x ++ ,y ++ ; update(); break; case 2 : scanf( " %d%d%d%d " , & L, & B, & R, & T); L ++ ,B ++ ,R ++ ,T ++ ; ans = compute(R,T) - compute(L - 1 ,T) - compute(R,B - 1 ) + compute(L - 1 ,B - 1 ); printf( " %d\n " ,ans); break; } } return 0 ; }
]]>hdu 1251(綆鍗晅rie) http://www.shnenglu.com/zoyi-zhang/archive/2008/05/07/49150.htmlzoyi zoyi Wed, 07 May 2008 12:32:00 GMT http://www.shnenglu.com/zoyi-zhang/archive/2008/05/07/49150.html http://www.shnenglu.com/zoyi-zhang/comments/49150.html http://www.shnenglu.com/zoyi-zhang/archive/2008/05/07/49150.html#Feedback 0 http://www.shnenglu.com/zoyi-zhang/comments/commentRss/49150.html http://www.shnenglu.com/zoyi-zhang/services/trackbacks/49150.html 鎴戜互涓烘槸trie涓殑絀洪棿娌¢噴鏀炬帀錛屾墍浠ユ敼鐢ㄤ簡閫掑綊鍒犻櫎錛岀粨鏋?00ms,宸窛闃匡紝浠ュ悗瑕佹敞鎰忎簡 鍐欒繖閬撻涓昏鏄涔犱竴涓嬶紝浠ヤ笅鏄唬鐮侊紝姣斾互鍓嶅啓鐨勭畝鍖栦簡寰堝
#include < iostream > #include< algorithm > #define MaxN 26 const char stdt = ' a'; using namespace std; struct trie { trie * next [MaxN]; int val; trie() { int i; for (i = 0 ;i < MaxN;i ++ ) next [i] = 0 ; val = 0 ; } ~trie() { int i; for (i = 0 ;i < MaxN;i ++ )delete( next [i]); } }; int main() { char words[ 12 ], * t; int ans; trie * root = new trie, * p; while (gets(words) && strcmp(words, "" )){ p = root; t = words; while ( * t){ if (p -> next [ * t - stdt] == 0 ) p -> next [ * t - stdt] = new trie; p = p -> next [ * t - stdt]; (p -> val) ++ ; t ++ ; } } while (scanf( " %s " ,words)! = EOF){ p = root; t = words; while ( * t){ if (p -> next [ * t - stdt] == 0 ){ ans = 0 ; break;} p = p -> next [ * t - stdt]; ans = p -> val; t ++ ; } printf( " %d\n " ,ans); } return 0 ; }
]]> eoj 2104 (鎻愰棶錛氳甯繖瑙g瓟涓嬫垜鐨勯棶棰樺搱) http://www.shnenglu.com/zoyi-zhang/archive/2008/04/29/48476.htmlzoyi zoyi Tue, 29 Apr 2008 11:17:00 GMT http://www.shnenglu.com/zoyi-zhang/archive/2008/04/29/48476.html http://www.shnenglu.com/zoyi-zhang/comments/48476.html http://www.shnenglu.com/zoyi-zhang/archive/2008/04/29/48476.html#Feedback 1 http://www.shnenglu.com/zoyi-zhang/comments/commentRss/48476.html http://www.shnenglu.com/zoyi-zhang/services/trackbacks/48476.html 闃呰鍏ㄦ枃 ]]> trie鏍?騫舵煡闆?/title> http://www.shnenglu.com/zoyi-zhang/archive/2008/04/08/46538.htmlzoyi zoyi Tue, 08 Apr 2008 10:35:00 GMT http://www.shnenglu.com/zoyi-zhang/archive/2008/04/08/46538.html http://www.shnenglu.com/zoyi-zhang/comments/46538.html http://www.shnenglu.com/zoyi-zhang/archive/2008/04/08/46538.html#Feedback 1 http://www.shnenglu.com/zoyi-zhang/comments/commentRss/46538.html http://www.shnenglu.com/zoyi-zhang/services/trackbacks/46538.html http://acm.pku.edu.cn/JudgeOnline/problem?id=2513 榪欓亾棰樻槸鐩存帴鎷垮墠鍑犲ぉ鍐欏緱妯$増鏀圭殑錛涘仛浜嗗嚑涓慨鏀?br>棣栧厛鍒犳帀浜唖earch錛岃繖閬撻鐨勭‘涓嶉渶瑕侊紝鏈潵娌″垹錛屼唬鐮佸疄鍦ㄥお闀?閫煎緱鎴戞病鍔炴硶 絎簩涓紝鎶妕rie涓璶um[]鐨勬剰鎬濇敼鎺変簡錛宯um[]鐜板湪瀛樼殑鏄瓧絎︿覆鍦ㄤ竴涓暟緇勭殑鏍囪錛?br>鐩稿綋浜巑ap鐨勫疄鐜幫紝閫氳繃榪欐牱鎴戞妸涓涓瓧絎︿覆鍜屼竴涓爣鍙峰搴斾笂浜嗭紝鏂逛究浜嗗茍鏌ラ泦鐨勬搷浣?br>鏋滅劧寰堜箙娌$騫舵煡闆嗕簡錛屼竴鍐欏氨鍑洪棶棰橈紝 涓昏鏄垜union_set鏄眳鐒跺繕浜嗚鍏坒ind_set涓涓嬶紝榪欐牱鍐欓拡瀵逛笅闈㈣繖緇勬暟鎹氨浼氬嚭鐜伴棶棰橈細 a b b a a a 榪樻湁涓涓氨鏄繖閬撻鐨勭┖杈撳叆闂錛岃杈撳嚭possible錛岃屼笉鏄疘mpossible 涓涓嬫槸鎴戠殑鍨冨溇浠g爜錛岃窇浜?00澶氾紝鏈夎皝鏈夋洿濂界殑鍙戞垜閭鍝? zhangjia888334@sohu.com
#include < iostream > #include< cstring > #define keyNum 26 #define MaxN 500005 struct node{ int parent; int rank; int num; // 榪欎釜棰滆壊鍑虹幇鐨勬鏁?br> node() { num = rank = 0 ; parent =- 1 ; } }; node colour[MaxN]; int id = 0 ; // 鏁扮粍鏍囪 struct trie{ struct trieNode{ // trie緇撶偣鐨勭粨鏋?br> trieNode * link[keyNum]; // 涓嬫爣涓?nbsp; ' a' , 'b' , 'c' , , 'z' 鐨勬寚閽堟暟緇?/span> int num[keyNum]; // 鎻掑叆榪欎釜鍗曡瘝鍦ㄦ暟緇勪腑鐨勪綅緗?br> trieNode(){ memset(num, - 1 ,sizeof(num)); //- 1琛ㄧず榪樻湭鎻掑叆鏁扮粍 memset(link, NULL ,sizeof(link)); } void init(){ memset(link, NULL ,sizeof(link)); memset(num, - 1 ,sizeof(num)); } }; trieNode * root; trie() { root = (trieNode * )malloc(sizeof(trieNode)); // 鍒濆鍖栨椂涓簉oot鐢寵浜嗙┖闂?br> root -> init(); } int Insert(char []); // 榪斿洖鏁扮粍涓殑浣嶇疆 void Delete(trieNode * ); // 閲婃斁絀洪棿 }; void trie::Delete(trieNode * t) { int i; for (i = 0 ;i < keyNum;i ++ ) if (t -> link[i])Delete(t -> link[i]); memset(t -> num, 0 ,sizeof(t -> num)); delete(t); } int trie::Insert(char x[]) { trieNode * current = root; int i = 1 ; while (x[i]){ if (current -> link[x[i - 1 ] - ' a']==NULL){ current -> link[x[i - 1 ] - ' a']=(trieNode*)malloc(sizeof(trieNode)); (current -> link[x[i - 1 ] - ' a'])->init(); } current = current -> link[x[i - 1 ] - ' a']; i ++ ; } if (current -> num[x[i - 1 ] - ' a']==-1) current -> num[x[i - 1 ] - ' a']=id++; colour[current -> num[x[i - 1 ] - ' a']].num++;//鍑虹幇鐨勬鏁?+ return current -> num[x[i - 1 ] - ' a']; } void init() { int i; for (i = 0 ;i < MaxN;i ++ ) colour[i].parent = i; } void union_set( int x, int y) { if (colour[x].rank > colour[y].rank) colour[y].parent = x; else { colour[x].parent = y; if (colour[x].rank == colour[y].rank) colour[y].rank ++ ; } } int find_set( int x) { if (x! = colour[x].parent) colour[x].parent = find_set(colour[x].parent); return colour[x].parent; } bool comman_father() { int i,p = 0 ; p = find_set( 0 ); for (i = 1 ;i < id;i ++ ) if (find_set(i)! = p)return false ; return true ; } void solve() { if (comman_father() == false ){ printf( " Impossible\n " ); return; } int i,head_end = 0 ; for (i = 0 ;i < id;i ++ ) if (colour[i].num% 2 == 1 ) // 鍒ゆ柇澶村拰灝?br> head_end ++ ; if (head_end == 2 ||!head_end) // 涓涓病鍥炶礬錛屼竴涓槸鏈夊洖璺?br> printf( " Possible\n " ); else printf( " Impossible\n " ); } int main() { char colr1[ 12 ],colr2[ 12 ]; trie a; int ncolr1,ncolr2; init(); while (scanf( " %s%s " ,colr1,colr2)! = EOF){ ncolr1 = a.Insert(colr1); ncolr2 = a.Insert(colr2); union_set(find_set(ncolr1),find_set(ncolr2)); } // 涓嬮潰鍒ゆ柇鏈夊嚑涓猵arent錛岃嫢鏈夊涓け璐?br> solve(); a.Delete(a.root); return 0 }
]]> trie 鏍?/title> http://www.shnenglu.com/zoyi-zhang/archive/2008/04/06/46355.htmlzoyi zoyi Sun, 06 Apr 2008 05:09:00 GMT http://www.shnenglu.com/zoyi-zhang/archive/2008/04/06/46355.html http://www.shnenglu.com/zoyi-zhang/comments/46355.html http://www.shnenglu.com/zoyi-zhang/archive/2008/04/06/46355.html#Feedback 3 http://www.shnenglu.com/zoyi-zhang/comments/commentRss/46355.html http://www.shnenglu.com/zoyi-zhang/services/trackbacks/46355.html 鎵浠ヨ繕鏄噰鐢ㄧ畝鍖栫増鐨則rie鏍?br> 榪欎釜搴旇綆楁槸姣旇緝鏍囧噯鐨則rie鏍戠粨鏋勶紝浣嗘槸浠栫殑鎻掑叆瀹炵幇璧鋒潵涓嶄粎浠呮槸鎻掑叆鏈韓鐨勫崟璇嶏紝鍙兘榪橀渶瑕佷慨鏀瑰師鏉ョ殑鏁扮粨鏋?br>姣斿璇存湰韜凡緇忓瓨鍦ㄤ簡bobwhite錛岀幇鍦ㄦ坊鍔燽obwhq錛屽氨瑕佸湪絎簩灞傜殑鍩虹涓婄戶緇墿灞曪紝bobwhite鐨勪綅緗篃瑕侀噸鏂板畾浣嶏紝鍒犻櫎鎿嶄綔涔熸槸榪欐牱 鍙兘榪樿涓婄Щ鏌愪簺鍗曡瘝錛岃繖涓槰澶╄瘯浜嗗緢涔咃紝鍐欏嚭鏉ョ殑閮戒笉琛屻?br>鑰屼笖瀵硅繖縐嶅瓧鍏告爲鐨勭粨鏋勬湰韜垜鐨勭悊瑙e氨寰堟販涔便?br>綆鍖栫増鐨則rie鏍?br> 浠ヤ笅榪欑瀹炵幇鏂規硶鏄牴鎹埆浜烘敼緙栫殑錛屾槰澶╄閫煎緱娌″姙娉曡繕鏄寰楃畝鍖栫増鐨勶紝紿佺劧鍙戠幇涓墰浜虹殑鍐欐硶鍜屾垜鐨勫緢鐩鎬技錛堣繖鐫瀹炶繕璁╂垜嬋鍔ㄤ簡涓嬩笅錛夛紝灝辮竟瀛︿範杈規敼浜嗭紝鍛靛懙 瀹冩槸鏍規嵁鏉數鐨勪竴閬撻鏉ュ啓鐨勶紝浠ヤ笅鏄垜鐨勪唬鐮侊細http://acm.hdu.edu.cn/showproblem.php?pid=1247
#include < iostream > #define keyNum 26 #define MaxN 50 struct trie{ struct trieNode{// trie緇撶偣鐨勭粨鏋?br> trieNode * link[keyNum]; // 涓嬫爣涓?nbsp; ' A' , 'B' , 'C' , , 'Z' 鐨勬寚閽堟暟緇?/span> int num[keyNum]; // 鎻掑叆key鐨勬鏁?br> trieNode(){ memset(num, 0 ,sizeof(num)); memset(link, NULL ,sizeof(link)); } void init(){ memset(link, NULL ,sizeof(link)); memset(num, 0 ,sizeof(num)); } }; trieNode * root; trie() { root = (trieNode * )malloc(sizeof(trieNode)); // 鍒濆鍖栨椂涓簉oot鐢寵浜嗙┖闂?br> root -> init(); } bool Search(char * ); void Insert(char []); void Delete(trieNode * ); }; bool trie::Search(char * x) { if ( * x == 0 )return false ; trieNode * current = root; x ++ ; while ( * x){ if (current -> link[ * (x - 1 ) - ' a']) current = current -> link[ * (x - 1 ) - ' a']; else break; x ++ ; } if ( * x == 0 && current -> num[ * (x - 1 ) - ' a']) return true ; else return false ; } void trie::Delete(trieNode * t) { int i; for (i = 0 ;i < keyNum;i ++ ) if (t -> link[i])Delete(t -> link[i]); memset(t -> num, 0 ,sizeof(t -> num)); delete(t); } void trie::Insert(char x[]) { trieNode * current = root; int i = 1 ; while (x[i]){ if (current -> link[x[i - 1 ] - ' a']==NULL){ current -> link[x[i - 1 ] - ' a']=(trieNode*)malloc(sizeof(trieNode)); (current -> link[x[i - 1 ] - ' a'])->init(); } current = current -> link[x[i - 1 ] - ' a']; i ++ ; } (current -> num[x[i - 1 ] - ' a'])++; } char c[ 50000 ][MaxN],tmp; int main() { trie a; int i = 0 ,j,num; while (scanf( " %s " ,c[i])! = EOF) a.Insert(c[i ++ ]); num = i; for (i = 0 ;i < num;i ++ ) for (j = 1 ;c[i][j];j ++ ){ tmp = c[i][j]; c[i][j] = 0 ; if (a.Search(c[i])){ c[i][j] = tmp; if (a.Search( & c[i][j])){ printf( " %s\n " ,c[i]); break;} } else c[i][j] = tmp; } a.Delete(a.root); return 0 ; }
榪欎釜妯$増榪樹笉鏄緢瀹屽杽~鐢ㄨ搗鏉ヨ繕鏄笉澶ф柟渚匡紝姣斿鍒犻櫎鑺傜偣錛屾垜鐨勫垹闄ゅ彧鏄啓浜嗗垹鎵鏈夌殑錛岀敤閫掑綊鍐欑殑銆?br>榪樻湁閬嶅巻鑺傜偣錛岄兘涓嶆槸寰堟柟渚跨殑銆?br>浠ヤ笂浠g爜瑙i噴鍑犵偣錛?br>棣栧厛鎴戞瀯閫犱簡涓鏍紅rie鐨勭粨鏋勶細鍦ㄦ緇撴瀯涓湁root錛屽拰榪欐5鏍戠殑鍩烘湰涓変釜鎿嶄綔 鍐嶆trie緇撴瀯涓殑姣忎釜鑺傜偣閮芥槸trieNode鐨勭粨鏋勶紝鍖呮嫭root涔熸槸 榪欐5鏍戞槸鍔ㄦ佺敓鎴愮殑錛屾墍浠ュtrieNode鐨刬nit寰堥噸瑕侊紝榪欑偣鍐欒繃鐨勫氨鐭ラ亾錛屼笉Init浼氬嚭鐜板緢澶氶棶棰樼殑, 鍦╰rieNode緇撴瀯涓富瑕佹湁26涓猯ink鍜?6涓猲um錛屽垰寮濮嬫垜鑷繁鍐欑殑鏃跺欏氨鏄繖26涓猲um鎼炰笉娓咃紝鍙啓浜嗕竴涓猲um錛岃繖鏄鏍戠粨鏋勭殑鐞嗚В娣蜂貢閫犳垚鐨?br>num鍦ㄨ繖閲屾槸鏍囪榪欎釜鍗曡瘝鎻掑叆鐨勬鏁幫紝涓?琛ㄧず榪欎釜鍗曡瘝榪樻病鏈夎鎻掑叆榪?br>trieNode榪樻湁涓緢閲嶈鐨勬垚鍛樺嚱鏁板氨鏄痠nit浜嗐?
]]> pku 1182 椋熺墿閾?/title> http://www.shnenglu.com/zoyi-zhang/archive/2008/01/31/42293.htmlzoyi zoyi Thu, 31 Jan 2008 12:39:00 GMT http://www.shnenglu.com/zoyi-zhang/archive/2008/01/31/42293.html http://www.shnenglu.com/zoyi-zhang/comments/42293.html http://www.shnenglu.com/zoyi-zhang/archive/2008/01/31/42293.html#Feedback 0 http://www.shnenglu.com/zoyi-zhang/comments/commentRss/42293.html http://www.shnenglu.com/zoyi-zhang/services/trackbacks/42293.html
1 #include < iostream > 2 #define MaxN 50000 3 typedef struct { 4 int parent; 5 int rank; 6 int food; // 鎸囧悜椋熺墿綾?br> 7 int enemy; // 鎸囧悜澶╂晫綾?br> 8 }NODE; 9 NODE animal[MaxN+ 1 ]; 10 void init(int n) 11 {12 int i; 13 for (i = 1 ;i <= n;i ++ ){ 14 animal[i].parent= i; 15 animal[i].rank= 0 ; 16 animal[i].food=- 1 ; 17 animal[i].enemy=- 1 ; 18 }19 }20 int find_set( int x) 21 {22 if (x ==- 1 )return - 1 ; // 鏈変簺food錛宔nemy鎸囧悜 - 1 23 if (animal[x].parent! = x) 24 animal[x].parent= find_set(animal[x].parent); 25 return animal[x].parent;26 }27 int union_set( int x, int y) 28 {29 if (x ==- 1 )return y; 30 if (y ==- 1 )return x; 31 if (animal[x].rank > animal[y].rank){ 32 animal[y].parent= x; 33 return x;}34 else { 35 animal[x].parent= y; 36 if (animal[x].rank == animal[y].rank)animal[y].rank ++ ; 37 return y;}38 }39 void make(int x, int y, int fx, int fy, int ex, int ey) // 鍒涘緩x鍚儁鐨勫叧緋?br> 40 {41 int t,v,w; 42 t= union_set(fx,y); // 棣栧厛灝唝涓巟鐨刦ood鍚堝茍 43 v= union_set(x,ey); 44 w= union_set(ex,fy); 45 animal[v].enemy= w; 46 animal[v].food= t; 47 animal[t].enemy= v; 48 animal[t].food= w; 49 if (w! =- 1 ){ 50 animal[w].food= v; 51 animal[w].enemy= t;} 52 }53 int main() 54 {55 int N,K,i,wn = 0 ,x,y,fx,fy,ex,ey,oper; 56 int t,u,v; 57 scanf(" %d%d " , & N, & K); 58 init(N);59 for (i = 1 ;i <= K;i ++ ){ 60 scanf(" %d%d%d " , & oper, & x, & y); // oper涓?鐨勬椂鍊欒〃紺簒鍜寉鏄悓綾伙紝oper涓?鐨勬椂鍊欒〃紺簒鍚儁 61 if (x > N||y > N){wn ++ ;continue;} 62 x= find_set(x); 63 y= find_set(y); 64 fx= find_set(animal[x].food); // fx鍙兘鏄?/span>- 1 65 fy= find_set(animal[y].food); // fy涔熷彲鑳芥槸 - 1 66 ex= find_set(animal[x].enemy); 67 ey= find_set(animal[y].enemy); 68 if (x == y){ if (oper == 2 )wn ++ ;continue;} // 1 .x,y鍚岀被 69 if (fy == x){wn ++ ;continue;} // 3 .y鍚儀 70 if (fx == y){ if (oper == 1 )wn ++ ;continue;} // 2 .x鍚儁 71 if (oper == 2 )make(x,y,fx,fy,ex,ey); // 4 ..x鍜寉灝氭湭浜х敓鑱旂郴,鍒涘緩鑱旂郴錛岄鍏堟槸x鍚儁錛屽叾嬈鐨刦ood綾誨悆x 72 if (oper == 1 ){ // 4 ..x鍜寉灝氭湭浜х敓鑱旂郴,鍒涘緩鑱旂郴 73 t= union_set(x,y); 74 u= union_set(fx,fy); 75 v= union_set(ex,ey); 76 animal[t].food= u; 77 animal[t].enemy= v; 78 if (u! =- 1 ){ 79 animal[u].enemy= t; 80 animal[u].food= v;} 81 if (v! =- 1 ){ 82 animal[v].food= t; 83 animal[v].enemy= u;}} 84 }85 printf(" %d\n " ,wn); 86 return 0 ; 87 }
if(u!=-1)if(v!=-1)榪欓噷鎶樿吘浜嗘垜涓ゅぉ
]]>
香蕉久久av一区二区三区 |
香港aa三级久久三级 |
久久久亚洲欧洲日产国码aⅴ
|
久久精品国产2020 |
人妻无码中文久久久久专区 |
热久久国产精品 |
精品国产乱码久久久久久人妻 |
久久精品免费观看 |
国内精品久久久久影院薰衣草 |
久久精品国产99国产精偷
|
精品国产婷婷久久久 |
亚洲午夜无码AV毛片久久 |
精品久久久久久综合日本 |
久久99久久99精品免视看动漫 |
精品久久久久久国产免费了 |
久久精品中文騷妇女内射 |
亚洲国产精品无码久久青草 |
品成人欧美大片久久国产欧美... |
中文字幕无码免费久久 |
欧美色综合久久久久久 |
91精品观看91久久久久久 |
www久久久天天com |
伊人久久精品无码av一区 |
亚洲欧洲久久久精品 |
久久久人妻精品无码一区 |
国产精品免费久久 |
精品国产福利久久久 |
久久亚洲高清观看 |
国产精品久久成人影院 |
久久香蕉超碰97国产精品 |
色欲av伊人久久大香线蕉影院 |
亚洲国产成人精品久久久国产成人一区二区三区综
|
久久福利青草精品资源站免费 |
亚洲精品美女久久777777 |
亚洲成av人片不卡无码久久 |
久久嫩草影院免费看夜色 |
久久久久综合国产欧美一区二区
|
久久99国产精品尤物 |
久久男人Av资源网站无码软件 |
av色综合久久天堂av色综合在 |
亚洲狠狠婷婷综合久久久久 |