[Test room] 10.28

[Test room] 10.28

10.26 date of the original title battle, not a hand to it AK? ,jump over

Welcome to reprint ssw02's blog: https://www.cnblogs.com/ssw02/p/11755483.html


Goblin tribes

Portal connection:

T2

Analog click. After drawing look nature painting found that due to exchange radio frequency, in fact, we are asking for can be divided into three cases, record the number of times each character appears in the special sentence can be applied statistics.

Is divided into two even-odd one even an odd number two, specifically look at the code

#include<bits/stdc++.h>
using namespace std ;
inline int read(){
    int s=0 ; char g=getchar() ; while(g>'9'||g<'0')g=getchar() ; 
    while( g>='0'&&g<='9' )s=s*10+g-'0',g=getchar() ; return s; 
} 
inline int getc(){
    char g=getchar() ; while( g>'z'||g<'a')g=getchar() ; 
    return (int)g-'a'+1 ;
}
int cnt[30] , N , M , T ;
void  clear(){
    memset( cnt , 0 , sizeof(cnt) ) ;
} 
void  work1(){
    int opt = false ; 
    for( register int i = 1 ; i <= 26 ; ++i )
        if( cnt[i]%4 ){ opt = true ; break ; }
    if( opt )puts("No") ;
    else puts("Yes") ;
}
void  work2(){
    int opt = 0 , tot = ( N/2*2 )*( M/2*2 ) ;
    for( register int i = 1 ; i <= 26 ; ++i )
        if( cnt[i]%4 == 0 ){
            if( cnt[i] > tot )cnt[i] -= tot , tot = 0 ;
            else tot -= cnt[i] , cnt[i] = 0 ;
        }
        else if( cnt[i] > 4 ){
            int rd = cnt[i]/4*4 ;
            if( rd > tot )cnt[i] -= tot , tot = 0 ;
            else tot -= rd , cnt[i] -= rd ;
        }
    if( tot ){puts("No");return ;}
    for( register int i = 1 ; i <= 26 ; ++i )
        if( cnt[i]%2 )opt++ ;
    if( opt ){puts("No");return;}
    puts("Yes") ;
}
void  work3(){
    int opt = 0 , tot = ( N/2*2 )*( M/2*2 ) ;
    for( register int i = 1 ; i <= 26 ; ++i )
        if( cnt[i]%4 == 0 ){
            if( cnt[i] > tot )cnt[i] -= tot , tot = 0 ;
            else tot -= cnt[i] , cnt[i] = 0 ;
        }
        else if( cnt[i] > 4 ){
            int rd = cnt[i]/4*4 ;
            if( rd > tot )cnt[i] -= tot , tot = 0 ;
            else tot -= rd , cnt[i] -= rd ;
        }
    if( tot ){puts("No");return ;}
    for( register int i = 1 ; i <= 26 ; ++i )
        if( cnt[i]%2 )opt++ ;
    if( opt != 1 ){puts("No");return;}
    puts("Yes") ;
}
int main(){
    freopen("quilt.in","r",stdin) ;
    freopen("quilt.out","w",stdout) ;
    T = read() ; 
    while( T-- ){
        N = read() , M = read() ; int m1 ;  
        for( register int i = 1 ; i <= N ; ++i )
            for( register int j = 1 ; j <= M ; ++j )
                m1 = getc() , cnt[m1]++;
        int tag = 0 ;
        tag = (N%2)+(M%2) ;
        if( tag == 0 )work1() ; 
        else if( tag == 1 )work2() ;
        else work3() ;
        clear() ;
    }
    return 0 ;
}

T3

T3 is relatively complex: direct handling explanations

Original title.
First, the contribution of each mosquitoes are independent. If a mosquito after the k will be affected by the mosquito-point contribution so that mosquitoes answer is 1- (1-p / q) k.
With 1 bfs is determined over the point which points are affected by mosquito then be treated differently.
points of the tree n, m are leaf nodes.
algorithm 1:
for each mosquitoes, do it again bfs, O (m2) times bfs, complexity O (nm2), expect to score 10 points
algorithm 2:
through a bfs we can count the contribution of all the ants of a leaf node departure then only m times bfs can the complexity of O (nm). it is desirable to score 30 points.
algorithm 3:
for d = test point 0 of 3, only 1 point is controlled so after the mosquito 1 point will be the contribution of P / Q, we just need to count the number of mosquitoes after. . No. 1 spot this is a very good number expected to score 10 points.
algorithm 4:
for the p / q = test point 1, 4, mosquito long after the point to be controlled would die we just need to count how many mosquitoes at least. after a point to be controlled. our contribution to the root 1, F [i] i represents the number of sub-leaf nodes within the tree where, for each point to be controlled, to its l us statistics Path number of ca complexity of O (n) which partially divided tips on standard considered...
Algorithm 5:
Consider discussion of each path, calculating the number of points to be influenced this path passes after solving lca complexity should be O (m2logn), but the details are more people do not write the questions.
by the sixth and seventh test points, combined with the previous algorithm can get 70 points.
algorithm 6 (out of practice):
considered algorithms to expand 4 in this case the contribution of each mosquito is 1- (1-p / q) k. we can first 1 regardless that the front, the back of the (1-p / q) k and seek out, finally m(m-1) and subtract that on it.
path can be split into two at the LCA we consider how to obtain the contribution of a certain point of all paths and LCA. path can be split into two parts , came from a part of LCA leaf node, the other part is a leaf node come from another LCA. the two groups of two considered "semi-paths."
note G [i] for the i to all of the half-LCA paths . the sum of the contributions (i.e.: x for each leaf node in the subtree i, g [i] + = ( 1-p / q) k, k is controlled to the point x i on the path of half number) .g [i] can be obtained by O (n) the DP tree.
Next, we determined in each point of the path by the LCA g [i] and the contribution.
for point x, considering all its sons each contribution to the son (u, v) is G [U]
G [v] * (the p-1-/ q)
attention, (u, v) and (v, u) need to be considered once
direct violence pieces for each pair of his son time out. we can O (number of sons) distributive law of multiplication by the time complexity of calculated total time complexity is still O (n). space complexity is also O (n). However, constant may be large, so the topic and who gave 5s timeframe.
algorithm 6:
this title belongs to the tree path statistical problems, the tree can divide and conquer. Miscellaneous degree O (nlogn). Expect to score 50 points.
There may be players through constant vigorously card directly with AC tree divide and conquer this problem.

Guess you like

Origin www.cnblogs.com/ssw02/p/11755483.html