Uva 11093 Just Finish it up——思路题

xiaoxiao2021-02-28  102

#include <cstdio> #include <iostream> using namespace std; const int maxn = 100000 + 10; int n, a[maxn], b[maxn]; int main() { int T, flag = 0, i, j, sum; scanf("%d", &T); while (T--) { scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", &a[i]); for (int i = 0; i < n; i++) scanf("%d", &b[i]); printf("Case %d: ", ++flag); bool ok = false; for (i = 0; i < n; i++) { j = i, sum = 0; while (true) { sum += a[j] - b[j]; if (sum < 0) { j = (j + 1) % n; break; } else j = (j + 1) % n; if (j == i) { ok = true; break; } } if (ok) break; else { if (j > i) i = j - 1;//-1是为了抵消i++ else break; } } if (ok) printf("Possible from station %d\n", i + 1); else printf("Not possible\n"); } return 0; }
转载请注明原文地址: https://www.6miu.com/read-55804.html

最新回复(0)