vsCode
C++
#include <windows.h> //keep external terminal #include <bits/stdc++.h> using namespace std; typedef long long LL; int r, y, g, sum_ryg; LL waitTime(int k, int t, LL ans) { LL pos; if (k == 1) pos = (r - t + ans) % sum_ryg; else if (k == 2) pos = (sum_ryg - t + ans) % sum_ryg; else if (k == 3) pos = (r + g - t + ans) % sum_ryg; if (pos < r) return r - pos; else if (pos >= r && pos < (r + g)) return 0; else return sum_ryg - pos + r; } int main() { scanf("%d%d%d", &r, &y, &g); sum_ryg = r + y + g; int n; scanf("%d", &n); LL ans = 0; for (int i = 0; i < n; i++) { int k, t; scanf("%d%d", &k, &t); if (k == 0) ans += t; else ans = ans + waitTime(k, t, ans); } printf("%lld\n", ans);//注意!!!输出格式为【%lld】!!! system("pause"); //keep external terminal return 0; }