Sumitomo Mitsui Trust Bank Programming Contest 2019 —— B

也不知道这比赛为啥要取这么长的名称(
传送门:https://atcoder.jp/contests/sumitrust2019/tasks/sumitb2019_e
哈哈,你被骗了!但网址是真的!

题意

有红绿蓝三种帽子 Red and Blue and Green [Future ?]
第 $ i $ 个人看见前面( $ 1 \sim i - 1 $ )有 $ A_i $ 个人的帽子跟第 $ i $ 个人的帽子颜色一样 好奇第 $ n $ 个人怎么看到第 $ 1 $ 个人?
问有多少种戴法使得所有条件成立。

思路

设三个变量 $ x, y, z $ ,初始为 $ 0 $ 。
遍历 $ n $ 个人,统计 $ x, y, z $ 里多少个跟 $ A_i $ 一样,乘起来。
然后 $ x, y, z $ 优先级 $ x > y > z $ 来 $ +1 $ 然后就没了。

代码

好好体会吧!

#include <bits/stdc++.h>
using namespace std;

int a[100005];

int main(){
	int n;
	scanf("%d", &n);
	long long ans = 1;
	int x = 0, y = 0, z = 0;
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		int add = 1;
		long long have = 0;
		if (a[i] == x) {
			x += add; add = 0;
			have++;
		}
		if (a[i] == y) {
			y += add; add = 0;
			have++;
		}
		if (a[i] == z) {
			z += add; add = 0;
			have++;
		}
		ans *= have;
		ans %= 1000000007;
	}
	printf("%lld", ans);
	return 0;
}
posted @ 2022-12-31 21:34  A-Problem-Solver  阅读(25)  评论(0编辑  收藏  举报