A.kaptree

Code:

// 考点树的深度 难度 ⭐
// 保证树的根为1
// 标程
#include
#include
#include
#include
#include
using namespace std;

#define ll long long

const int N = 2105;
struct Node {
    int l,r;
}tree[N];

int max_len(int root,int cnt) {
    if(root == 0)
        return cnt-1;
    else {
        return max(max_len(tree[root].l,cnt+1),max_len(tree[root].r,cnt+1));
    }
}

int min_len(int root,int cnt) {
    if(root == 0)
        return cnt-1;
    else {
        //printf("root = %d, cnt == %d\n",root,cnt);
        int l = min_len(tree[root].l,cnt+1);
        int r = min_len(tree[root].r,cnt+1);
        return min(l,r);
    }
}

int main()
{
    int u,v,n;
    scanf("%d",&n);
    for(int i = 0;i < n; ++i) {
        scanf("%d%d",&u,&v);
        if(tree[u].l == 0)
            tree[u].l = v;
        else
            tree[u].r = v;
    }
    int k1 = min_len(1,0);
    int k2 = max_len(1,0);
    printf("%d\n",k2 + k1);
    return 0;
}

B.十字路口

#include
#include
#include
using namespace std;
#define inf 0x3f3f3f3f
#define N 301
int mp[N][N];
int main()
{
    int n,m;
    scanf("%d %d",&n,&m);
    memset(mp,inf,sizeof mp);
    for(int i=0;i

C.七段的符号

#include
#include
#include
using namespace std;
int f[][4]={{0,0,0,0},{2,6,0,0},{1,3,7,0},{2,4,7,0},{3,5,0,0},{4,6,7,0},{1,5,7,0},{2,3,5,6}};
int a[8],vis[8];
bool BFS(int p)
{
    queueq;
    q.push(p);
    while(q.size())
    {
        int x=q.front();
        q.pop();
        if(vis[x])continue;
        vis[x]=1;
        for(int i=0;i<4;++i)
        {
            int y=f[x][i];
            if(y==0)break;
            if(!vis[y]&&a[y])
                q.push(y);
        }
    }
    int kkk=0; 
    for(int i=1;i<=7;++i)
    {
        kkk+=a[i];
        if(a[i]!=vis[i])
            return false;
    }
    if(kkk==4)return false;//只能有一部分连通,结果验证 
    return true;
}
bool find()
{
    memset(vis,0,sizeof vis);
    for(int i=1;i<=7;++i)
        if(a[i])return BFS(i); 
    return false;
}
int main()
{
    int num=0,ci=0;
    for(a[1]=0;a[1]<=1;a[1]++)
    for(a[2]=0;a[2]<=1;a[2]++)
    for(a[3]=0;a[3]<=1;a[3]++)
    for(a[4]=0;a[4]<=1;a[4]++)
    for(a[5]=0;a[5]<=1;a[5]++)
    for(a[6]=0;a[6]<=1;a[6]++)
    for(a[7]=0;a[7]<=1;a[7]++)
        if(find())num++;
    printf("%d\n",num);
    return 0;
    //题解有多种,其他解可百度“E七段码” 
}

D.Xor Query

#include
using namespace std;
#define ll long long

const int N = 500005;
ll a[N],tree[N<<2];
int n,q;

int lowbit(int x) {
    return -x & x;
}

void updata(int loc,int x) {
    while(loc <= n) {
        tree[loc] ^= x;
        loc += lowbit(loc);
    }
}

ll get(int loc) {
    ll ans = 0;
    while(loc > 0) {
        ans ^= tree[loc];
        loc -= lowbit(loc);
    }
    return ans;
}

int main()
{

    scanf("%d%d",&n,&q);
    for(int i = 1; i <= n; ++i) {
        scanf("%lld",&a[i]);
        updata(i,a[i]);
    }
    int u,v,w;
    while(q--) {
        scanf("%d%d%d",&u,&v,&w);
        if(u == 1) {
            updata(v,w);
        }
        else {
            printf("%lld\n",get(w) ^ get(v-1));
        }
    }

    return 0;
}

E.A hard working man

    /** 
     * @Author: Mangata
     * @Date: 2021-02-28 15:50:13
     * @PID: 104
     * @Result: Accepted
     * Powered By DOJ
    */
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #define ll long long
    #include 
    using namespace std;
    bool dp[100][100] = {0}; // i, j 代表m n ,值代表输赢 

    int main() {
        dp[1][1] = false;
        for(int k = 3; k < 99; k++) {
            for(int n = 1; n < k; n++) {
                int m = k - n;
                bool &w = dp[n][k - n];
                w = false;
                for(int i = 1; i < n; i++){ // 清空右边的,并从左边的放i 个过来 
                    if(!dp[i][n - i]) w = true; // 如果下一个阶段为必败点,则当前为必胜点 
                }
                for(int i = 1; i < m; i++) {
                    if(!dp[i][m - i]) w = true;
                }
            }
        }
        int t;
        cin >> t;
        int a, b; 
        for(int i = 1; i <= t; i++) {
            cin >> a >> b;
            cout << dp[a][b] << endl;   
        }

        return 0;
    }

F.red bags

#include 
using namespace std;
int main() {
    int b[]={1,2,3,4,5,6,7,8,9,10},i,count=0;
    while(next_permutation(b,b+10)) {
        for(i=0;i<9;i++) 
            if(abs(b[i]-b[i+1])==1) break;
        if(i==9) count++;                       
    }
    cout<

本当の声を響かせてよ