USACO Combination Lock 发表于 2016-03-31 | 分类于 USACO Training , Chapter 1 Getting started , Section 1.3 | Notice that $n$ may be smaller than 5.Code12345678910111213141516171819202122232425262728293031323334/*ID: wcr19961PROG: comboLANG: C++11*/#include <cstdio>#include <cstring>#include <algorithm>#include <cstdlib>#include <string>#include <set>using namespace std;typedef long long LL;const int maxn = 5;int a[maxn], b[maxn];set<int> s[maxn];int main() { freopen("combo.in", "r", stdin); freopen("combo.out", "w", stdout); int n, ans = 1; scanf("%d", &n); scanf("%d%d%d", &a[0], &a[1], &a[2]); scanf("%d%d%d", &b[0], &b[1], &b[2]); for (int i = 0; i < 3; ++i) { if (a[i] < b[i]) { swap(a[i], b[i]); } ans *= max(0, 5 - min(a[i] - b[i], b[i] - a[i] + n)); } printf("%d\n", n > 5 ? 250 - ans : n * n * n); return 0;}