即日起在codingBlog上分享您的技术经验即可获得积分,积分可兑换现金哦。

Uva 11093 Just Finish it up之脑洞

编程语言 hao_zong_yin 17℃ 0评论
#include 
#include 

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;
}


转载请注明:CodingBlog » Uva 11093 Just Finish it up之脑洞

喜欢 (0)or分享 (0)
发表我的评论
取消评论

*

表情