UVA-11093加油站环形

在这里插入图片描述
题目链接

#include<bits/stdc++.h>
using namespace std;
int T,len;
const int MaxN=100001;
int p[MaxN],q[MaxN];
int main(){
    int tes=1;
    scanf("%d",&T);
    while(T--){
        // cout<<"test:"<<T<<endl;
        scanf("%d",&len);
        for(int i=0;i<len;i++)
            scanf("%d",&p[i]);
        for(int i=0;i<len;i++)
            scanf("%d",&q[i]);
        int start =0;
        for(;start<len;){
            int now=0,j;//当前油量
            for(j=start;j<len+start;j++){
                int t=j%len;
                now += p[t]-q[t];
                if(now<0){
                    start=j+1;
                    break;
                }
            }
            if(j==len+start) break;

        }
        printf("Case %d: ",tes++);
        if(start>=len)
            printf("Not possible\n");
            else
            {
                printf("Possible from station %d\n",start+1);
            }
            
            
                                                                                                      
        
        
    }
    return 0;
}
发布了239 篇原创文章 · 获赞 16 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/qq_38662930/article/details/104253376