Codeforces Round #564(div2)

Codeforces Round #564(div2)

Originally thought it was sent to breakout, the results become killed field.

Dish is original sin

A

SB questions, questions not read up on the pay out of WA, the code would not stick up

B

Simple structure

Obviously, \ (n-n-* \) matrix may be arranged in this order

VBUwCj.png

The then \ (n-\) size engage in a practice like

#include<cstdio>
#include<cctype>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<vector>
#define LL long long
#define pii pair<int,int>
#define mk make_pair
using namespace std;
const int N = 1e5 + 3;
inline int read(){
    int v = 0,c = 1;char ch = getchar();
    while(!isdigit(ch)){
        if(ch == '-') c = -1;
        ch = getchar(); 
    }
    while(isdigit(ch)){
        v = v * 10 + ch - 48;
        ch = getchar(); 
    }
    return v * c;
}
int n,m;
int aa[N];
int main(){
    n = read();
    aa[1] = 1;
    for(int i = 1;i <= 10000;++i) aa[i] = 2 * i - 1;
    int now = 1;
    while(aa[now] < n) now++;
    printf("%d\n",now);
    for(int i = 1;i <= now;++i)
    printf("1 %d\n",i);
    int cc = 2;
    for(int i = now + 1;i <= n;++i)
    printf("%d %d\n",cc,now),cc++;
    return 0;
}

C

Send proposition, card more than an hour, very thought of a topic

First of all, the answer is certainly not more than \ (the n-2 * \) , the worst case we will have a non-blank save cards in your hand and then shot one by one

We have two strategies

1: Direct play his cards, then need a team to meet the end of \ (1 \) at the end of the continuous fields beginning next card in our hands, which we can pass on so if a touch. the tail had consecutive sub-segments, then we can look directly into the sentence, Ruoguo can, obviously this is the optimal solution

2: When the tail does not meet the above conditions, we have no way connected to or continuous field, we have been saved card, in order to play at a time

We set \ (p_i \) represents \ (i \) position number plate in the queue (not in the queue regarded as \ (0 \) ), then, if all our in \ (p_i \) become the team's head of time (set as \ (t \) ) play

First of all needed \ (\ max_ {i = t } ^ npi - (i - 1) == p_i- (i - 1) \)

\ (p_i- (i - 1) \) is where the hardest to understand.

I understand we insert \ (i - 1 \) when times, there are only a few steps to be \ (i \) to get out (the default time we have we have \ (1-i - 1 \ ) )

In other words, I make sure hands are \ (1-i - 1 \ ) and then plug the least finished \ (i - 1 \) touch before \ (i \) must insert \ (p_i- (i - 1) \) times, because my hands \ (1-I- 1 \) , this is not a contribution (or partially overlapping counted only once)

But if this time we did not have a \ (i - 1 \) how to do?

It does not matter if this occurs \ (p_ {i - 1} \) must be in \ (p_i \) later, we get the maximum value, \ (P_ {i + 1} \) contribution is clearly larger

Therefore, the answer is \ (n + max_ {i = 1} ^ np_i-i + 1 \)

#include<cstdio>
#include<cctype>
#include<iostream>
using namespace std;
const int N = 2e5 + 3;
int p[N];
int a[N];
int b[N];
int book[N];
int n;
inline bool check(){
    for(int i = 1;i <=  n;++i) if(book[i] == 0) return false;
    return true;    
}
int main(){
    scanf("%d",&n);
    for(int i = 1;i <= n;++i) scanf("%d",&a[i]),book[a[i]] = 1;
    for(int i = 1;i <= n;++i) scanf("%d",&b[i]),p[b[i]] = i;
//  bool flag = 0;
    int now = n;
    while(now >= 2 && b[now - 1] != 0 && b[now - 1] == b[now] - 1) now--;
//  cout << now << endl;
    int t = 1;
    if(b[now] == 1){
        for(int i = 1;i <= b[n];++i) book[i] = 1;
        for(int i = b[n] + 1;i <= n;++i){
            if(!book[i]){break;}
            book[b[t]] = 1;
            t++;
        //  cout << t << endl;
        }
        if(check()){
            printf("%d\n",now - 1);
            return 0;   
        }
    }
//  cout << flag << endl;
//  cout << t << endl;
    //  cout << "GG";
        int ans = 0;
        for(int i = 1;i <= n;++i)
            ans = max(ans,p[i] - i + 1);
        printf("%d\n",ans + n);
    return 0;   
}

D

First, we found that every one sub-tree must be continuous arc of a circle, so every child a tree independently of each other, then we consider \ (DP \) seeking contributions

We fixed with, let \ (f_i \) represented by \ (i \) the answer is now time

\(f_i = (son_i + [i !=root])!\prod_{j\in son_i}f_j\)

\ (Nf_ ans = {root} \)

why

Think about every single child because the tree is so independently of each other's product and the total answer must answer the relevant sub-tree, and because there is no limit to their relative order

And so the number of factorial son relationship, but not the current parent node is now, to take part in the arrangement.

And now there \ (n \) positions can put

#include<cstdio>
#include<cctype>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include<cmath>
#define LL long long
#define pii pair<int,int>
#define mk make_pair
using namespace std;
const int N = 3e5 + 3;
const LL mod = 998244353;
vector <int> G[N];
LL ans = 0;
int son[N];
LL dp[N];
LL inv[N];
inline int read(){
    int v = 0,c = 1;char ch = getchar();
    while(!isdigit(ch)){
        if(ch == '-') c = -1;
        ch = getchar(); 
    }
    while(isdigit(ch)){
        v = v * 10 + ch - 48;
        ch = getchar(); 
    }
    return v * c;
}
int n;
inline void dfs(int x,int f){
    dp[x] = 1;
    for(int i = 0;i < (int)G[x].size();++i){
        int y = G[x][i];
        if(y == f) continue;
        dfs(y,x);   
        son[x]++; 
    }
    int w = (x != 1) ? son[x] + 1: son[x];
    for(int i = 0;i < (int)G[x].size();++i){
        int y = G[x][i];
        if(y == f) continue;
        dp[x] = dp[x] * dp[y] % mod;
    }
    dp[x] = dp[x] * inv[w] % mod;
}
int main(){
    inv[0] = 1;
    

    n = read();for(int i = 1;i <= n;++i) inv[i] = inv[i - 1] * i % mod;
    for(int i = 1;i < n;++i){
        int x = read(),y = read();
        G[x].push_back(y);
        G[y].push_back(x);  
    }
    dfs(1,0);
    printf("%I64d\n",dp[1] * n % mod);
    return 0;
}

Guess you like

Origin www.cnblogs.com/wyxdrqc/p/10990378.html