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
  • 相关阅读:
    iOS开发中多线程断点下载大文件
    iOS开发中的压缩以及解压
    iOS中大文件下载(单线程下载)
    NSURLConnection的GetPost方法
    自定义NSOperation下载图片
    NSOperation和NSOperationQueue的一些基本操作
    虚函数、继承
    new、delete、以及queue类
    new、delete、以及queue类
    在构造函数中使用new时的注意事项
  • 原文地址:https://www.cnblogs.com/Aragaki/p/8613217.html
Copyright © 2011-2022 走看看