生活随笔
收集整理的這篇文章主要介紹了
Codeforces Round #668 (Div. 2)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
前20分鐘做題,后面看題,二題戰士,賽后補題www
A - Permutation Forgery
直接逆序輸出即可
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#pragma GCC optimize(2)
#include <iostream>
#include <algorithm>
using namespace std
;
int n
;
int a
[ 110 ] ;
int main ( )
{ IO
; int T
; cin
>> T
; while ( T
-- ) { cin
>> n
; for ( int i
= 0 ; i
< n
; i
++ ) cin
>> a
[ i
] ; reverse ( a
, a
+ n
) ; for ( int i
= 0 ; i
< n
; i
++ ) cout
<< a
[ i
] << ' ' ; cout
<< endl
; } return 0 ;
}
B - Array Cancellation
考慮一個數組中的一個負數,如何至少花費多少代價變為0。 如果前面沒有正數必須要花費硬幣,否則就和前面的正數抵消。對于花費硬幣就和最后面的正數抵消,維護前綴和瞎搞一下即可。
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#pragma GCC optimize(2)
#include <iostream>
#include <algorithm>
using namespace std
;
typedef long long ll
;
const int N
= 100010 ;
int n
;
ll a
[ N
] ;
ll s
[ N
] ;
int main ( )
{ IO
; int T
; cin
>> T
; while ( T
-- ) { cin
>> n
; for ( int i
= 1 ; i
<= n
; i
++ ) cin
>> a
[ i
] ; for ( int i
= 1 ; i
<= n
; i
++ ) s
[ i
] = s
[ i
- 1 ] + a
[ i
] ; ll res
= 0 ; for ( int i
= 1 ; i
<= n
; i
++ ) if ( a
[ i
] < 0 ) res
- = min ( 0ll , s
[ i
- 1 ] + res
+ a
[ i
] ) ; cout
<< res
<< endl
; } return 0 ;
}
C - Balanced Bitstring
這題一直沒想出來,賽后看題解也想了一會兒,我好菜啊 考慮對于長度為kk k 的窗口在原串上移動,移動的過程中最前面的字符被彈出窗口s[i]s[i] s [ i ] ,新加入一個字符s[i+k]s[i+k] s [ i + k ] ,如果要保證窗口內11 1 的數量和00 0 的數量不變,那么必須滿足s[i]=s[i+k]s[i]=s[i+k] s [ i ] = s [ i + k ] ,如果上述條件滿足能夠保證所有長度為kk k 的子串11 1 的數量和00 0 的數量相等,在只需判斷第一個窗口內11 1 的個數和00 0 的個數是否不大于k2\frac{k}{2} 2 k ? 即可
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#pragma GCC optimize(2)
#include <iostream>
#include <algorithm>
using namespace std
;
const int N
= 300010 ;
int n
, k
;
int a
[ N
] ;
int main ( )
{ IO
; int T
; cin
>> T
; while ( T
-- ) { cin
>> n
>> k
; for ( int i
= 0 ; i
<= n
; i
++ ) a
[ i
] = - 1 ; string s
; cin
>> s
; bool ok
= 1 ; for ( int i
= 0 ; i
< n
; i
++ ) { int j
= i
% k
; if ( s
[ i
] == '?' ) continue ; else { if ( a
[ j
] == - 1 ) a
[ j
] = s
[ i
] - '0' ; else { if ( a
[ j
] != s
[ i
] - '0' ) ok
= 0 ; } } } if ( ok
) { int cnt0
= 0 , cnt1
= 0 ; for ( int i
= 0 ; i
< k
; i
++ ) cnt0
+ = a
[ i
] == 0 , cnt1
+ = a
[ i
] == 1 ; if ( cnt0
> k
/ 2 || cnt1
> k
/ 2 ) ok
= 0 ; } if ( ok
) cout
<< "YES" << endl
; else cout
<< "NO" << endl
; } return 0 ;
}
D - Tree Tag
Bob想要贏的充要條件 ① 最初的dist(a,b)>dadist(a,b) >da d i s t ( a , b ) > d a 如果不滿足,第一步直接就可以到b所在的點 ② 樹的直徑>2×da>2×da > 2 × d a 如果不滿足,a可以想辦法跳到樹的中心,然后就在一步之內到達任意點 ③ db>2×dadb>2×da d b > 2 × d a 如果不滿足,每次a想辦法與b保持da的距離,那么b一定不斷遠離a,知道不能遠離的時候就不能跳出范圍,然后就輸了。 這也太難想了吧,想出來的都是神仙
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#pragma GCC optimize(2)
#include <iostream>
#include <algorithm>
using namespace std
;
typedef long long ll
;
typedef pair
< ll
, ll
> pll
;
const int N
= 100010 ;
int n
, a
, b
, da
, db
;
int h
[ N
] , e
[ N
* 2 ] , ne
[ N
* 2 ] , idx
;
int dep
[ N
] ;
int dlen
;
void add ( int a
, int b
)
{ e
[ idx
] = b
; ne
[ idx
] = h
[ a
] ; h
[ a
] = idx
++ ;
}
int dfs1 ( int u
, int fa
)
{ int d1
= 0 , d2
= 0 ; for ( int i
= h
[ u
] ; i
!= - 1 ; i
= ne
[ i
] ) { int j
= e
[ i
] ; if ( j
== fa
) continue ; int d
= 1 + dfs1 ( j
, u
) ; if ( d
> d1
) d2
= d1
, d1
= d
; else if ( d
> d2
) d2
= d
; } dlen
= max ( dlen
, d1
+ d2
) ; return d1
;
}
void dfs2 ( int u
, int fa
)
{ dep
[ u
] = dep
[ fa
] + 1 ; for ( int i
= h
[ u
] ; i
!= - 1 ; i
= ne
[ i
] ) { int j
= e
[ i
] ; if ( j
== fa
) continue ; dfs2 ( j
, u
) ; }
}
int main ( )
{ IO
; int T
; cin
>> T
; while ( T
-- ) { cin
>> n
>> a
>> b
>> da
>> db
; for ( int i
= 1 ; i
<= n
; i
++ ) h
[ i
] = - 1 , dep
[ i
] = 0 ; idx
= 0 ; dlen
= 0 ; for ( int i
= 1 ; i
< n
; i
++ ) { int a
, b
; cin
>> a
>> b
; add ( a
, b
) , add ( b
, a
) ; } dfs1 ( 1 , 0 ) ; dfs2 ( a
, 0 ) ; int dist
= dep
[ b
] - dep
[ a
] ; if ( dist
> da
&& dlen
> 2 * da
&& db
> 2 * da
) cout
<< "Bob" << endl
; else cout
<< "Alice" << endl
; } return 0 ;
}
要加油哦~
總結
以上是生活随笔 為你收集整理的Codeforces Round #668 (Div. 2) 的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔 網站內容還不錯,歡迎將生活随笔 推薦給好友。