在算法竞赛中”hack”一般指用一组测试数据触发程序的缺陷,从而导致本来通过题目的 AC 代码无法通过该测试数据。 一般情况见得比较多的是用 hack 数据导致别人 WA 掉,当然也有一些会导致原本的 AC 代码 TLE 和 MLE。 牛牛在一些简单的练习题时遇到了这样一个问题。 给定一个大小为 $n$ 的数组 $a(1 \leq a_i \leq 10^9)$,然后请你判断数组元素是否能够从中选出三个组成一个三角形。
牛牛发现AC通过的代码中有这样一种暴力逻辑,该逻辑的伪代码如下。
1 2 3 4 5 6 7 8 9 10 11 12
FOR i = 1 ... n FOR j = i + 1 ... n FOR k = j + 1 ... n IF isTriangle(a[i],a[j],a[k]) print("yes") EXIT END IF END FOR END FOR END FOR print("no") EXIT
intmain(){ scanf("%d", &t); while (t--) { scanf("%d %d", &n, &k); int s = sqrt(n); printf("%d\n", k <= s ? k : 2 * s - n / k + (s != n / s)); } return0; }
classSolution { private: int cnt1[30] = {0}, cnt2[30] = {0}; public: boolcheck(){ int flag = 1; for (int i = 0; i < 26; i++) { if (cnt1[i] != cnt2[i]) flag = 0; } return flag; }
boolcheckInclusion(string s1, string s2){ if (s1.size() > s2.size()) return0; int n = s1.size(), m = s2.size(); for (int i = 0; i < n; i++) cnt1[s1[i] - 'a']++, cnt2[s2[i] - 'a']++; if (check()) return1; for (int i = n; i < m; i++) { cnt2[s2[i - n] - 'a']--; cnt2[s2[i] - 'a']++; if (check()) return1; } return0; } };
usingnamespace std; typedeflonglong ll; const ll mod = 998244353; constint N = 1e6 + 5; ll n, m, F[N + 1], I[N + 1];
ll power(ll a, ll b){ return b ? power(a * a % mod, b / 2) * (b % 2 ? a : 1) % mod : 1; }
voidinit(){ F[0] = 1; for (ll i = 1; i <= N; i++) F[i] = F[i - 1] * i % mod; I[N] = power(F[N], mod - 2); for (ll i = N; i--;) { I[i] = I[i + 1] * (i + 1) % mod; } }
ll C(ll n, ll k){ return F[n] * I[n - k] % mod * I[k] % mod; }
intmain(){ init(); cin >> n >> m; ll ans = 0; for (ll i = 0; i <= n - 1; i++) { ans = (ans + (n - i) % mod * C(i + 1 + m - 3, m - 2) % mod * i) % mod; } cout << ans << endl; return0; }
In the Republic of AtCoder, there are N cities numbered 1 through N and M railroads numbered 1 through M.
Railroad i connects City $A_i$ and City $B_i$ bidirectionally. At time 0, $K_i$, and all subsequent multiples of $K_i$, a train departs from each of these cities and head to the other city. The time each of these trains takes to reach the destination is $T_i$.
You are now at City X. Find the earliest time you can reach City Y when you start the journey by taking a train that departs City X not earlier than time 0. If City Y is unreachable, report that fact.
The time it takes to transfer is ignorable. That is, at every city, you can transfer to a train that departs at the exact time your train arrives at that city.