• Educational Codeforces Round 15 [111110]


    注意一个词:连续

    #include<stdio.h>
    #include<stdlib.h>
    #include<string.h>
    #include<bits/stdc++.h>
    using namespace std;
    long long a[110000];
    int main()
    {
        //freopen("input.txt","r",stdin);
        int n;
        scanf("%d", &n);
        for (int i = 1; i <= n; i++)
            scanf("%I64d", &a[i]);
        int ans = 1;
        int i = 2, tmp = 1;
        while (i <= n)
        {
            if (a[i - 1] < a[i]) tmp++;
            else
            {
                if (tmp > ans) ans = tmp;
                tmp = 1;
            }
            i++;
        }
        if (tmp > ans) ans = tmp;
        printf("%d
    ", ans);
        //fclose(stdin);
        return 0;
    }
    View Code

    枚举每个可能的和,用map记下每种值有多少个,n个数过一遍,每次加上和减去当前值的差的值的个数。当当前值本身是2的幂时要额外减一。

    int和longlong一起运算时最好把int弄成longlong

     

    #include <iostream>
    #include <map>
    using namespace std;
    
    map<long long, int> e;
    long long a[110000];
    
    int main()
    {
        int n;
        cin >> n;
        for (int i = 1; i <= n; i++)
            cin >> a[i];
        e.clear();
        for (int i = 1; i <= n; i++)
            e[a[i]]++;
        long long sum = 0;
        for (int i = 1; i <= n; i++)
            sum += a[i];
        long long ans = 0;
        for (int i = 1; i <= n; i++)
        {
            long long tmp = 0;
            for (long long j = 1; j <= sum; j <<= 1)
            {
                if (j <= a[i]) continue;
                long long f = j - a[i];
                tmp += e[f];
                if (f == a[i]) tmp--;
            }
            ans += tmp;
        }
        cout << ans / 2 << endl;
        //system("pause");
        return 0;
    }
    View Code

    用二分法找到每个点最近的塔的距离,所有距离中最大的就是最小的满足条件的r。

    #include <iostream>
    #include <map>
    using namespace std;
    
    __int64 a[110000], b[110000];
    
    int main()
    {
        int n, m;
        cin >> n >> m;
    
        for(int i = 1; i <= n; i++)
            cin >> a[i];
    
        for(int i = 1; i <= m; i++)
            cin >> b[i];
    
        __int64 MAX = 0;
    
        for(int i = 1; i <= n; i++)
        {
            __int64 tmp = 1e15;
    
            if(a[i] <= b[1]) tmp = b[1] - a[i];
            else if(b[m] <= a[i]) tmp = a[i] - b[m];
            else
            {
                int l = 1, r = m, mid;
    
                while(1)
                {
                    mid = (l + r) >> 1;
    
                    if(a[i] < b[mid]) r = mid;
                    else l = mid;
    
                    if(l == r || l + 1 == r) break;
                }
    
                tmp = a[i] - b[l];
    
                if(b[r] - a[i] < tmp) tmp = b[r] - a[i];
            }
    
            if(tmp > MAX) MAX = tmp;
        }
    
        cout << MAX << endl;
        //system("pause");
        return 0;
    }
    View Code

    跟VJ上的守望者的逃离差不多。

    #include <iostream>
    #include <map>
    using namespace std;
    
    
    int main()
    {
        long long d, k, a, b, t;
        cin >> d >> k >> a >> b >> t;
    
        if(d <= k)
        {
            cout << d*a << endl;
            return 0;
        }
    
        long long ans = k * a;
        d -= k;
        long long p = d / k;
    
        if(t + k * a < k * b) ans += (t + k * a) * p;
        else ans += k * b * p;
    
        d %= k;
    
        if(t + d * a < d * b) ans += (t + d * a);
        else ans += d * b;
    
        cout << ans << endl;
        //system("pause");
        return 0;
    }
    View Code

    这题只说一句:快速幂。

    >技不如人,甘拜下风。

    >相当精彩的比赛。

    #include <iostream>
    #include <string>
    #include <map>
    using namespace std;
    int f[110000][50], fa[110000];
    long long SUM[110000][50], MIN[110000][50], w[110000];
    long long Asum[110000], Amin[110000];
    int Ap[110000];
    int main()
    {
        long long n, k;
        cin >> n >> k;
        for (int i = 0; i < n; i++)
            cin >> fa[i];
        for (int i = 0; i < n; i++)
            cin >> w[i];
        for (int i = 0; i < n; i++)
        {
            f[i][0] = fa[i];
            SUM[i][0] = w[i];
            MIN[i][0] = w[i];
        }
        for (int i = 1; i <= 45; i++)
        {
            for (int j = 0; j < n; j++)
            {
                int x = f[j][i - 1];
                f[j][i] = f[x][i - 1];
                SUM[j][i] = SUM[j][i - 1] + SUM[x][i - 1];
                MIN[j][i] = MIN[j][i - 1];
                if (MIN[j][i - 1] > MIN[x][i - 1]) MIN[j][i] = MIN[x][i - 1];
            }
        }
        memset(Asum, 0, sizeof(Asum));
        for (int i = 0; i < n; i++)
        {
            Amin[i] = 1e15;
            Ap[i] = i;
        }
        for (int i = 0; i <= 45; i++)
        {
            if ((k & ((long long)1 << i)) == 0) continue;
            for (int j = 0; j < n; j++)
            {
                int x = Ap[j];
                Asum[j] += SUM[x][i];
                if (Amin[j] > MIN[x][i]) Amin[j] = MIN[x][i];
                Ap[j] = f[x][i];
            }
        }
        for (int i = 0; i < n; i++)
            cout << Asum[i] << " " << Amin[i] << endl;
        //system("pause");
        return 0;
    }
    View Code

     

  • 相关阅读:
    URLProtocol服务协议
    ODBC、OLEDB和ADO之间的关系 ,以及性能比较
    如何在VS2015查看C#界面窗体里的控件层次
    SpeechVoiceSpeakFlags枚举类型的详细解释
    SQL中遇到多条相同内容只取一条的最简单实现方法
    flink elasticsearch sink table 忽略部分字段开发
    flink elasticsearch source table 集成elasticsearch-hadoop connector开发
    记一次python 协程给合多线程死锁问题
    kubernetes gitlab runner java maven ci/cd 整体方案示例
    某云elasticsearch节点失效,手动重置primary,迁移分区
  • 原文地址:https://www.cnblogs.com/dramstadt/p/5761702.html
Copyright © 2020-2023  润新知