發表文章

目前顯示的是 7月, 2020的文章

random生成一顆樹

用了那個啥prufer還啥的序列的啥的東西,然後這是用在generator上的之類的,最後如果要改成一般的話就改main前面幾行就好了,大概吧。 #include <bits/stdc++.h> using namespace std ; int n ; vector < int > t ; set < int > s ; multiset < int > tt ; signed main ( int argc, char * argv [ ] ) { registerGen ( argc, argv, 1 ) ; int n = atoi ( argv [ 1 ] ) ; for ( int i = 1 ; i <= n - 2 ; ++ i ) t. push_back ( rand ( ) % n + 1 ) ; for ( int i = 1 ; i <= n ; ++ i ) s. insert ( i ) ; for ( auto i : t ) cout << i << " " ; cout << endl ; for ( auto i : t ) { if ( s. find ( i ) ! = s. end ( ) ) s. erase ( s. find ( i ) ) ; tt. insert ( i ) ; } for ( auto i : t ) { auto it = s. begin ( ) ; cout << * it << " " << i << endl ; s. erase ( it ) ; tt. erase ( tt. find ( i ) ) ; if ( tt. find ( i ) == tt. end ( ) ) s. insert ( i ) ;