#include<cstdio>
#include<iostream>
#include<set>
#include<algorithm>
const int maxn=100000+5;
int p[maxn],q[maxn],n;
using namespace std;
int go(int s){
int fuel=p[s]-q[s];
for(int i=(s+1)%n;i!=s;i=(i+1)%n){
if(fuel<0) return i;
fuel+=p[i]-q[i];
}
if(fuel<0) return -1;// 进行到这一步还没return说明到达情况s-1到s fuel<0 说明不存在解 填return s会导致错误答案
return s;
}
int solve(){
int start=0;
for(;;){
int finish=go(start);
if(finish<start) return -1;
if(finish==start) return start;
start=finish;
}
}
int main(){
int T;
cin>>T;
for(int kase=1;kase<=T;kase++){
cin>>n;
for(int i=0;i<n;i++)
cin>>p[i];
for(int i=0;i<n;i++)
cin>>q[i];
int ans=solve();
printf("Case %d: ", kase);
if(ans < 0) printf("Not possible\n");
else printf("Possible from station %d\n", ans+1);
}
system("pause");
return 0;
}
8.5-246-uva11093-just finish it up-模拟法
最新推荐文章于 2024-07-29 14:21:11 发布