日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

2015.7.17( NOI2015 day1 )

發布時間:2024/6/18 编程问答 47 豆豆
生活随笔 收集整理的這篇文章主要介紹了 2015.7.17( NOI2015 day1 ) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

今天早起做了NOI2015網絡同步賽....

最近NOI是越來越向NOIP靠攏了....但是我還是不會做.....

?

第一題:程序自動分析

先離散化一下..然后最多就剩20w個數 , 不等于就存起來..等于就用并查集維護...最后for判斷一下就行了.....

-------------------------------------------------------------------------------------

#include<cstdio>#include<cstring>#include<algorithm>#include<iostream>#include<cctype>#include<cstdlib>#define rep(i ,n) for(int i=0; i < n; ++i)#define clr(x ,c) memset(x, c, sizeof(x))using namespace std;const int maxn = 200005;struct T {int x;T* next;} *head[ maxn ] , pool[ maxn ] , *pt;void add( int u , int v ) {pt -> x = v;pt -> next = head[ u ];head[ u ] = pt++;}inline int read() {char c = getchar();int ans = 0;for( ; ! isdigit( c ) ; c = getchar() );for( ; isdigit( c ) ; c = getchar() ) ? ?ans = ans * 10 + c - '0';return ans;}int fa[ maxn ];int find( int x ) {return x == fa[ x ] ? x : fa[ x ] = find( fa[ x ] );}struct Q {int x , y;bool type;} q[ maxn ];int id[ maxn << 1 ];int main(){freopen("prog.in", "r", stdin);freopen("prog.out", "w", stdout);int t = read();while( t-- ) {int cnt = 0;pt = pool;int n = read();rep( i , n ) {Q &p = q[ i ]; ? ?id[ cnt++ ] = p.x = read();id[ cnt++ ] = p.y = read();p.type = read();}sort( id , id + cnt );cnt = unique( id , id + cnt ) - id;rep( i , cnt ) fa[ i ] = i;clr( head , 0 );rep( i , n ) {Q* p = q + i;if( p -> type )? ? ?fa[ find( lower_bound( id , id + cnt , p -> x ) - id ) ] =? ? ? ? ?find( lower_bound( id , id + cnt , p -> y ) - id );else? ? ?add( lower_bound( id , id + cnt , p -> x ) - id , ? ? ? ? lower_bound( id , id + cnt , p -> y ) - id );}bool ans = true;rep( i , cnt ) {for( T* p = head[ i ] ; p ; p = p -> next ) { ? ?if( find( i ) == find( p -> x ) ) {ans = false;break; ? ?}}if( ! ans ) break;}printf( ans ? "YES\n" : "NO\n" );}return 0;}?

-------------------------------------------------------------------------------------

?第二題 : 軟件包管理器

樹鏈剖分... install( x ) 就處理 x 到 root 的這條路徑 , uninstall( x ) 就處理以 x 為根的子樹...子樹在線段樹上是連續的.. 兩個操作都可以打標...話說我對拍時暴力程序也跑得很快...難道暴力也能過 ?

-------------------------------------------------------------------------------------

#include<cstdio>#include<cstring>#include<algorithm>#include<iostream>#include<cctype>#include<cstdlib>#define rep(i ,n) for(int i=0; i < n; ++i)#define clr(x ,c) memset(x, c, sizeof(x))#define REP( x ) for( edge* e = head[ x ] ; e ; e = e -> next )#define M( l , r ) ( ( ( l ) + ( r ) ) >> 1 )using namespace std;const int maxn = 100000 + 5;struct edge {int to;edge* next;} E[ maxn << 1 ] , *ptt = E , *head[ maxn ];inline void add( int u , int v ) {ptt -> to = v;ptt -> next = head[ u ];head[ u ] = ptt++;}#define add_edge( u , v ) add( u , v ) , add( v , u )int top[ maxn ] , fa[ maxn ] , dep[ maxn ] , size[ maxn ] , son[ maxn ];int id[ maxn ] , id_cnt = 0 , TOP , n , _L[ maxn ] , _R[ maxn ];void dfs( int x ) {size[ x ] = 1 , son[ x ] = -1;REP( x ) {int to = e -> to;if( to == fa[ x ] ) continue;dep[ to ] = dep[ x ] + 1;fa[ to ] = x;dfs( to );size[ x ] += size[ to ];if( son[ x ] == -1 || size[ son[ x ] ] < size[ to ] )? ? son[ x ] = to;}}void DFS( int x ) {top[ x ] = TOP;_L[ x ] = id[ x ] = ++id_cnt;if( son[ x ] != -1 ) DFS( son[ x ] );REP( x ) if( fa[ x ] != e -> to && e -> to != son[ x ] ) ? ?DFS( TOP = e -> to );_R[ x ] = id_cnt;}void init() {dfs( dep[ 0 ] = 0 );DFS( TOP = 0 );}struct Node {Node *l , *r;int set , sum; // sum : sum of installNode() {set = sum = 0;l = r = NULL;}inline void update( int len ) {if( set != -1 ) ? ?sum = set * len;else? ? ?sum = l -> sum + r -> sum;}inline void pushdown() {if( set != -1 ) {l -> set = r -> set = set;set = -1;}}} pool[ maxn << 1 ] , *pt = pool , *root;void build( Node* t , int l , int r ) {if( r > l ) {int m = M( l , r );build( t -> l = pt++ , l , m );build( t -> r = pt++ , m + 1 , r );}}int L , R;bool v;// v -> true installvoid modify( Node* t , int l , int r ) {if( L <= l && r <= R ) {t -> set = v;} else {int m = M( l , r );t -> pushdown();L <= m ? modify( t -> l , l , m ) : t -> l -> update( m - l + 1 );m < R ? modify( t -> r , m + 1 , r ) : t -> r -> update( r - m );}t -> update( r - l + 1 );}int query( Node* t , int l , int r ) {if( L <= l && r <= R )return v ? r - l + 1 - t -> sum : t -> sum;int m = M( l , r );t -> pushdown();t -> l -> update( m - l + 1 );t -> r -> update( r - m );return ( L <= m ? query( t -> l , l , m ) : 0 ) +? ? ? ? ( m < R ? query( t -> r , m + 1 , r ) : 0 );}int install( int x , int y ) {int ans = 0;while( top[ x ] != top[ y ] ) {if( dep[ top[ x ] ] < dep[ top[ y ] ] ) swap( x , y );L = id[ top[ x ] ] , R = id[ x ];ans += query( root , 1 , n );modify( root , 1 , n );x = fa[ top[ x ] ];}if( dep[ x ] < dep[ y ] ) swap( x , y );L = id[ y ] , R = id[ x ];ans += query( root , 1 , n );modify( root , 1 , n );return ans;}inline int read() {char c = getchar();int ans = 0;for( ; ! isdigit( c ) ; c = getchar() );for( ; isdigit( c ) ; c = getchar() ) ? ?ans = ans * 10 + c - '0';return ans;}int main(){freopen("manager.in", "r", stdin);freopen("manager.out", "w", stdout);clr( head , 0 );n = read();build( root = pt++ , 1 , n );rep( i , n - 1 ) {int t = read(); ? ?add_edge( t , i + 1 );}init();int q = read() , x;char s[ 10 ];while( q-- ) {scanf( "%s%d" , s , &x );if( s[ 0 ] == 'i' ) {v = true;printf( "%d\n" , install( 0 , x ) );} else {v = false;L = _L[ x ] , R = _R[ x ];printf( "%d\n" , query( root , 1 , n ) );modify( root , 1 , n );}}return 0;}?

-------------------------------------------------------------------------------------?

第三題 : 壽司晚宴

完全不會..但是打表還能弄點分吧....暴力程序打個表然后就30分了...

-------------------------------------------------------------------------------------

#include<cstdio>#include<cstring>#include<algorithm>#include<iostream>#include<cctype>#include<cstdlib>#define rep(i ,n) for(int i=0; i < n; ++i)#define clr(x ,c) memset(x, c, sizeof(x))using namespace std;typedef long long ll;const int maxn = 50;ll ans[ maxn ];int main(){freopen("dinner.in", "r", stdin);freopen("dinner.out", "w", stdout);ans[ 2 ] = 3;? ? ans[ 3 ] = 9;? ? ans[ 4 ] = 21;? ? ans[ 5 ] = 63;? ? ans[ 6 ] = 111;? ? ans[ 7 ] = 333;? ? ans[ 8 ] = 693;? ? ans[ 9 ] = 1521;? ? ans[ 10 ] = 2577;? ? ans[ 11 ] = 7731;? ? ans[ 12 ] = 13491;? ? ans[ 13 ] = 40473;? ? ans[ 14 ] = 67833;? ? ans[ 15 ] = 119241;? ? ans[ 16 ] = 239481;? ? ans[ 17 ] = 718443;? ? ans[ 18 ] = 1340523;? ? ans[ 19 ] = 4021569;? ? ans[ 20 ] = 7494849;? ? ans[ 21 ] = 13356657;? ? ans[ 22 ] = 22271409;? ? ans[ 23 ] = 66814227;? ? ans[ 24 ] = 130266387;? ? ans[ 25 ] = 268286823;? ? ans[ 26 ] = 447212583;? ? ans[ 27 ] = 896472063;? ? ans[ 28 ] = 1684872063;? ? ans[ 29 ] = 5054616189;ll n , MOD;cin >> n >> MOD;? ? if( n < 30 ) cout << ans[ n ] % MOD << "\n";? ? else cout << 1LL * rand() * rand() % MOD << "\n";return 0;}?

-------------------------------------------------------------------------------------

?后天還有day2...沒玩過提答題 , 挺想玩的....

轉載于:https://www.cnblogs.com/JSZX11556/p/4654928.html

總結

以上是生活随笔為你收集整理的2015.7.17( NOI2015 day1 )的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。