Welcome to Liukejie'|

liukejie

园龄:1年8个月粉丝:5关注:11

2023-07-01 10:28阅读: 6评论: 0推荐: 0

AT_sumitb2019_e Colorful Hats 2 题解

思路

一道数学智力题。

因为 n 的范围是 105,所以我们考虑 O(n) 解决。

统计现在总共有多少个红,蓝,绿的帽子,再判断有多少种颜色的帽子个数是和输入的数相等的,表示当前有多少种方案,最后累乘一下即可。

代码如下

#include <bits/stdc++.h>

using namespace std;

#define int long long 
#define rep(i, l, r) for(int i = l; i <= r; ++ i)
#define per(i, r, l) for(int i = r; i >= l; -- i)
#define me0(a); memset(a, 0, sizeof a);
#define me3(a); memset(a, 0x3f, sizeof a);
#define PII pair<int, int>
#define il inline

const int INF = 0x3f3f3f3f, MOD = 1e9 + 7;

il void read(int &n)
{
    bool w = 0;
    char c = getchar();
    for(; c < 48 || c > 57; c = getchar())
        w = c == 45;
    for(n = 0; c >= 48 && c <= 57; c = getchar())
        n = n * 10 + c - 48;
    n = w ? -n : n;
}

il void write(int x, char a)
{
    char c[40], s = 0;
    if(x < 0) putchar(45), x = -x;
    for(; x ;) c[s ++] = x % 10, x /= 10;
    if(!s) putchar(48);
    for(; s -- ;) putchar(c[s] + 48);
    putchar(a);
}

const int MAXN = 100000;

int n;
int ans = 1;
int m[4];
main()
{
    read(n);
    rep(i, 1, n)
    {
        int x;
        read(x);
        int sum = 0, t = 0;
        if(x == m[1]) ++ sum, t = 1;
        if(x == m[2]) ++ sum, t = 2;
        if(x == m[3]) ++ sum, t = 3;
        ans *= sum;
        ans %= MOD;
        ++ m[t];
    }
    cout << ans << '\n';

    return 0;
}
posted @   liukejie  阅读(6)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起