zoukankan      html  css  js  c++  java
  • Codeforces 932 数组环构造 树上LCA倍增

    A

    #include <bits/stdc++.h>
    #define PI acos(-1.0)
    #define mem(a,b) memset((a),b,sizeof(a))
    #define TS printf("!!!
    ")
    #define pb push_back
    #define inf 1e9
    //std::ios::sync_with_stdio(false);
    using namespace std;
    //priority_queue<int,vector<int>,greater<int>> que; get min
    const double eps = 1.0e-8;
    typedef pair<int, int> pairint;
    typedef long long ll;
    typedef unsigned long long ull;
    const int maxn = 3e7 + 10;
    const int  maxm = 300;
    const int turn[4][2] = {{1, 0}, { -1, 0}, {0, 1}, {0, -1}};
    //priority_queue<int, vector<int>, less<int>> que;
    //next_permutation
    ll mod = 1e9 + 7;
    int main()
    {
            string a;
            cin >> a;
            string ans;
            ans = a;
            for (int i = 1; i <= a.size(); i++)
            {
                    ans += a[a.size() - i];
            }
            cout << ans << endl;
            return 0;
    }
    View Code

    B

    #include <bits/stdc++.h>
    #define PI acos(-1.0)
    #define mem(a,b) memset((a),b,sizeof(a))
    #define TS printf("!!!
    ")
    #define pb push_back
    #define inf 1e9
    //std::ios::sync_with_stdio(false);
    using namespace std;
    //priority_queue<int,vector<int>,greater<int>> que; get min
    const double eps = 1.0e-8;
    typedef pair<int, int> pairint;
    typedef long long ll;
    typedef unsigned long long ull;
    const int maxn = 3e7 + 10;
    const int  maxm = 300;
    const int turn[4][2] = {{1, 0}, { -1, 0}, {0, 1}, {0, -1}};
    //priority_queue<int, vector<int>, less<int>> que;
    //next_permutation
    int ans[1000005][10];
    ll mod = 1e9 + 7;
    int getans(int x)
    {
            if (x < 10)
            {
                    return x;
            }
            else
            {
                    int cur = 1;
                    while (x > 0)
                    {
                            if (x % 10 != 0)
                            {
                                    cur *= x % 10;
                            }
                            x /= 10;
                    }
                    return getans(cur);
            }
    }
    int main()
    {
            for (int i = 1; i <= 1000001; i++)
            {
                    int now = getans(i);
                    for (int j = 1; j <= 9; j++)
                    {
                            ans[i][j] = ans[i - 1][j];
                    }
                    ans[i][now]++;
            }
            int q;
            cin >> q;
            int l, r, k;
            for (int i = 1; i <= q; i++)
            {
                    scanf("%d %d %d", &l, &r, &k);
                    cout << ans[r][k] - ans[l - 1][k] << endl;
            }
            return 0;
    }
    View Code

    C

    构造题  要求构造出一个数列满足下列条件 

    可以看成构造有向图里面的环

    #include <bits/stdc++.h>
    #define PI acos(-1.0)
    #define mem(a,b) memset((a),b,sizeof(a))
    #define TS printf("!!!
    ")
    #define pb push_back
    #define inf 1e9
    //std::ios::sync_with_stdio(false);
    using namespace std;
    //priority_queue<int,vector<int>,greater<int>> que; get min
    const double eps = 1.0e-8;
    typedef pair<int, int> pairint;
    typedef long long ll;
    typedef unsigned long long ull;
    const int maxn = 3e7 + 10;
    const int  maxm = 300;
    const int turn[4][2] = {{1, 0}, { -1, 0}, {0, 1}, {0, -1}};
    //priority_queue<int, vector<int>, less<int>> que;
    //next_permutation
    int ans[1000005][10];
    ll mod = 1e9 + 7;
    int main()
    {
            int n, a, b;
            cin >> n >> a >> b;
            int x, y;
            x = y = -1;
            int cnt = n / a;
            for (int i = 0; i <= cnt; i++)
            {
                    if ((n - i * a) % b == 0)
                    {
                            x = i;
                            y = (n - i * a) / b;
                            break;
                    }
            }
            if (x == -1)
            {
                    cout << -1 << endl;
                    return 0;
            }
            int cur = 0;
            for (int i = 1; i <= x; i++)
            {
                    cout << cur + a << " ";
                    for (int j = 1; j <= a - 1; j++)
                    {
                            cout << cur + j << " ";
                    }
                    cur += a;
            }
            for (int i = 1; i <= y; i++)
            {
                    cout << cur + b << " ";
                    for (int j = 1; j <= b - 1; j++)
                    {
                            cout << cur + j << " ";
                    }
                    cur += b;
            }
            //cout << endl;
            return 0;
    }
    View Code

    D

    https://www.cnblogs.com/AWCXV/p/8453152.html

    https://www.cnblogs.com/forever97/p/cf463.html

    #include <bits/stdc++.h>
    #define PI acos(-1.0)
    #define mem(a,b) memset((a),b,sizeof(a))
    #define TS printf("!!!
    ")
    #define pb push_back
    #define inf 1e9
    //std::ios::sync_with_stdio(false);
    using namespace std;
    //priority_queue<int,vector<int>,greater<int>> que; get min
    const double eps = 1.0e-10;
    const double EPS = 1.0e-4;
    typedef pair<int, int> pairint;
    typedef long long ll;
    typedef unsigned long long ull;
    //const int maxn = 3e5 + 10;
    const int turn[4][2] = {{1, 0}, { -1, 0}, {0, 1}, {0, -1}};
    //priority_queue<int, vector<int>, less<int>> que;
    //next_permutation
    const int N = 4e5;
    const int M = 20;
    const ll INF = 1e16;
    int Q;
    ll last, W[N + 10], sum[N + 10][M + 10];
    int f[N + 10][M + 10], cnt = 1;
    int main()
    {
            cin >> Q;
            for (int i = 0; i <= 20; i++)
            {
                    sum[1][i] = sum[0][i] = INF;
            }
            W[0] = INF;
            for(int i=1;i<=Q;i++)
            {
                    ll ope, p, q;
                    cin >> ope >> p >> q;
                    if (ope == 1)
                    {
                            ll R = p ^ last, w = q ^ last;
                            cnt++;
                            W[cnt] = w;
                            if (W[R] >= w)
                            {
                                    f[cnt][0] = R;
                            }
                            else
                            {
                                    ll now = R;
                                    for (int i = 20; i >= 0; i--)
                                            if (W[f[now][i]] < w)
                                            {
                                                    now = f[now][i];
                                            }
                                    f[cnt][0] = f[now][0];
                            }
                            for (int i = 1; i <= 20; i++)
                            {
                                    f[cnt][i] = f[f[cnt][i - 1]][i - 1];
                            }
    
                            sum[cnt][0] = W[f[cnt][0]];
    
                            for (int i = 1; i <= 20; i++)
                            {
                                    if (f[cnt][i] == 0)
                                    {
                                            sum[cnt][i] = INF;
                                    }
                                    else
                                    {
                                            sum[cnt][i] = sum[cnt][i - 1] + sum[f[cnt][i - 1]][i - 1];
                                    }
                            }
                    }
                    else
                    {
                            ll R = p ^ last, X = q ^ last;
                            int len = 0;
                            if (X < W[R])
                            {
                                    cout << 0 << endl;
                                    last = 0;
                                    continue;
                            }
                            X -= W[R];
                            len++;
                            for (int i = 20; i >= 0; i--)
                            {
                                    if (X >= sum[R][i])
                                    {
                                            X -= sum[R][i];
                                            R = f[R][i];
                                            len += (1 << i);
                                    }
                            }
                            cout << len << endl;
                            last = len;
                    }
            }
            return 0;
    }
    View Code
  • 相关阅读:
    apache和tomcat有什么不同,为什么要整合apache 和tomcat
    使用jstack分析cpu消耗过高的问题
    eclipse建立springMVC 简单项目
    JAVA中的反射机制
    MySQL索引的Index method中btree和hash的优缺点
    JAVA中的线程安全与非线程安全
    Java中普通代码块,构造代码块,静态代码块执行顺序
    jvm的内部体系结构浅析
    CPU思考
    linux内核调度算法(2)--CPU时间片如何分配 转!
  • 原文地址:https://www.cnblogs.com/Aragaki/p/8613217.html
Copyright © 2011-2022 走看看