zoukankan      html  css  js  c++  java
  • codeforce Hello 2018 913 ABCDEFG SOL

    A:

      我们发现2^n增长很快,n>30时便没有贡献了。

    #include<bits/stdc++.h>
    using namespace std;
    int n,m;
    int main () {
        scanf("%d%d",&n,&m);
        if (n>29) {printf("%d
    ",m);return 0;}
        int l=1<<n; l--;
        printf("%d
    ",m&l);
    }

    B

      我们dfs一边就好了。

    #include<bits/stdc++.h>
    using namespace std;
    #define sight(c) ('0'<=c&&c<='9')
    #define N 10007
    inline void read(int &x){
        static char c;
        for (c=getchar();!sight(c);c=getchar());
        for (x=0;sight(c);c=getchar())x=x*10+c-48;
    }
    int n,fa,son[N],tot,tog;
    int fall[N],net[N],head[N];
    inline void add(int x,int y){
       fall[++tot]=y; net[tot]=head[x]; head[x]=tot;
    }
    bool dfs(int x){
        int r=0;
        for (int i=head[x];i;i=net[i])  {
            if (!head[fall[i]]) r++;
            else if (!dfs(fall[i])) return 0;
        }
        if (r<3) return 0; return 1;
    }
    int main () {
        read(n);
        for (int i=2;i<=n;i++) 
         read(fa),add(fa,i);
        puts(dfs(1)?"Yes":"No");
    }

    C :

    我们采取贪心的策略,我们先用A[i]去更新其后面的数据:

    举个例子 a[1]=10 ,a[2]=100,那么我们发现a[2]永远比a[1] 劣,那么我们用a[1]的两倍更新a[2].

    我们再从高位向下做,我们发现对于每一个ai,(更新过的),我们要么取一个(L在这一位上有1),或是再多取一个,从而不取之后的数据,采取这种策略O(N)扫一遍就好了。

    D :sol点这里 (整理在一起太长了。)

    E :sol点这里

    F :sol点这里

    G:sol点这里

  • 相关阅读:
    遗传算法
    UVa 11584 Partitioning by Palindromes
    UVa1625 Color Length
    UVa10003 Cutting Sticks
    UVa1347 Tour
    UVa116 (单向TSP,多决策问题)
    uVa 12563 Jin Ge Jin Qu
    模糊综合评判
    Python进阶(5)_进程与线程之协程、I/O模型
    Python进阶(4)_进程与线程 (python并发编程之多进程)
  • 原文地址:https://www.cnblogs.com/rrsb/p/8289771.html
Copyright © 2011-2022 走看看