题解:P15359 「WYZOI R2」春运
Charged_Charge · · 题解
思路:
数学题。先考虑暴力,很显然直接枚举天数模拟就行了,但
代码:
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 3e3+10;
int d, n, m, t;
int ans;
int a[N];
signed main() {
cin >> d >> n >> m >> t;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n * m; i++) {
if (i % m == 0) {
int x = a[n - 1];
for (int j = n - 1; j >= 0; j--) {
a[j] = a[j - 1];
}
a[0] = x;
}
ans = (ans + a[i % n]) % d;
}
ans = ((ans % d) * (t / (n * m) % d) % d) % d;
t %= (n * m);
for (int i = 0; i < t; i++) {
if (i % m == 0) {
int x = a[n - 1];
for (int j = n - 1; j >= 0; j--) {
a[j] = a[j - 1];
}
a[0] = x;
}
ans = (ans + a[i % n]) % d;
}
cout << ans % d;
return 0;
}