Just Finish it up UVA - 11093

假设当前从p点开始进行判断,如果仅仅只能走到q点,那么我们下次就从q+1点开始进行模拟与判断,因为从p点到后续的点如果可达,那么到达后续的点的油量>=0,此时如果从这些点都不能继续向后推进,那么再次判断油量为0的情况就没意义了,也就是重复判断了,具体实现见如下代码:

#include<iostream>
#include<vector>
#include<string>
#include<set>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<deque>
#include<functional>
using namespace std;

int main(){
	int T;
	cin >> T;
	for (int Case = 1; Case <= T; Case++){
		int n;
		cin >> n;
		vector<int> p;
		vector<int> q;
		for (int i = 0; i < n; i++){
			int t;
			cin >> t;
			p.push_back(t);
		}
		for (int i = 0; i < n; i++){
			int t;
			cin >> t;
			q.push_back(t);
		}
		int startID = 0;
		while (startID < n){
			int start = startID;
			int res = 0, step;
			for (step = 0; step < n; step++){
				if (res + p[start] - q[start] < 0){
					break;
				}
				else{
					res += p[start] - q[start];
					start = (start + 1) % n;
				}
			}
			if (step == n){
				break;
			}
			else{
				startID += step+1;
			}
		}
		cout << "Case " << Case << ":";
		if (startID < n){
			cout <<" Possible from station "<< startID + 1<<endl;
		}
		else{
			cout << " Not possible\n";
		}
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值