• [NOIP2014D1]


    T1

    Problem

    洛谷

    Solution

    一道非常裸的模拟题。直接枚举每次猜拳就可以了。

    Code

    #include<cmath>
    #include<cstdio>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    using namespace std;
    #define ll long long
    int x[205], y[205];
    ll read()
    {
        ll ans = 0; int zf = 1; char ch;
        while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
        if (ch == '-') zf = -1, ch = getchar();
        while (ch >= '0' && ch <= '9') ans = ans * 10 + ch - '0', ch = getchar();
        return ans * zf;
    }
    int check(int X, int Y)
    {
        if (X == Y) return 0;
        if (X == 0)
            if (Y == 2 || Y == 3) return 1;
            else return -1;
        if (X == 1)
            if (Y == 0 || Y == 3) return 1;
            else return -1;
        if (X == 2)
            if (Y == 1 || Y == 4) return 1;
            else return -1;
        if (X == 3)
            if (Y == 2 || Y == 4) return 1;
            else return -1;
        if (X == 4)
            if (Y == 0 || Y == 1) return 1;
            else return -1;
    }
    int main()
    {
        int n = read(), XX = read(), YY = read();
        for (int i = 0; i < XX; i++) x[i] = read();
        for (int i = 0; i < YY; i++) y[i] = read();
        int ansx = 0, ansy = 0;
        for (int time = 0; time < n; time++)
        {
            int X = x[time % XX], Y = y[time %YY];
            if (check(X, Y) == 1) ansx++;
            else if (check(X, Y) == -1) ansy++;
        }
        printf("%d %d
    ", ansx, ansy);
    }
    

    T2

    Problem

    洛谷

    Solution

    这题其实只要枚举每个点,选它的两条边构成一对,记录max和sum。
    求sum注意一下用前缀和优化就好了,求max只需算每个点连着的点中最大的两个点相乘的最大值。

    Code

    #include<cmath>
    #include<cstdio>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    using namespace std;
    #define ll long long
    ll read()
    {
        ll ans = 0; int zf = 1; char ch;
        while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
        if (ch == '-') zf = -1, ch = getchar();
        while (ch >= '0' && ch <= '9') ans = ans * 10 + ch - '0', ch = getchar();
        return ans * zf;
    }
    int vet[400005], head[200005], nextx[400005];
    ll w[200005], num = 0;
    const ll mo = 10007;
    void add(int u, int v)
    {
        vet[++num] = v;
        nextx[num] = head[u];
        head[u] = num;
    }
    int main()
    {
        int n = read();
        for (int i = 1; i < n; i++)
        {
            int u = read(), v = read();
            add(u, v);
            add(v, u);
        }
        for (int i = 1; i <= n; i++) w[i] = read();
        ll ans = 0, maxX = 0;
        for (int u = 1; u <= n; u++)
        {
            ll First = 0, Second = 0, sum = 0;
            for (int i = head[u]; i; i = nextx[i])
            {
                int v = vet[i];
                if (w[v] > First)
                {
                    Second = First;
                    First = w[v];
                }
                else if (w[v] > Second) Second = w[v];
                ans = (ans + 2 * sum * w[v]) % mo;
                maxX = max(maxX, First * Second);
                sum += w[v];
            }
        }
        printf("%lld %lld
    ", maxX, ans);
    }
    
  • 相关阅读:
    【随手记录】PG数值类型记录
    【SkyWalking】 Can't find service by service instance id from cache, service instance id is:xxx
    【随手记录】定时邮件发送限制 SMTPSendFailedException:557
    【随手记录】IDEA一个工程打开多个项目
    【随手记录】时间格式转换报错:while it seems to fit format 'yyyy-MM-dd'T'HH:mm:ss.SSSZ'
    【随手记录】实体类里方法自动执行问题
    【随手记录】IDEA的工具mode切换
    【随手记录】MagicNumber 魔数 在协议里作用
    js singleton
    js 对象的深层嵌套函数对对象属性的访问
  • 原文地址:https://www.cnblogs.com/WizardCowboy/p/7785014.html
Copyright © 2020-2023  润新知