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\n", 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\n", maxX, ans);
}
posted on 2017-11-04 23:15  WizardCowboy  阅读(81)  评论(0编辑  收藏  举报