Alaska

题目描写叙述

Problem B: Alaska

The Alaska Highway runs 1422 miles from Dawson Creek, British Columbia to Delta Junction, Alaska. Brenda would like to be the first person to drive her new electric car the length of the highway. Her car can travel up to 200 miles once charged at a special charging station. There is a charging station in Dawson Creek, where she begins her journey, and also several charging stations along the way. Can Brenda drive her car from Dawson City to Delta Juntion and back?

输入要求

The input contains several scenario. Each scenario begins with a line containing n, a positive number indicating the number of charging stations. nlines follow, each giving the location of a filling station on the highway, including the one in Dawson City. The location is an integer between 0 and 1422, inclusive, indicating the distance in miles from Dawson Creek. No two filling stations are at the same location. A line containing 0 follows the last scenario.

输出要求

For each scenario, output a line containing POSSIBLE if Brenda can make the trip. Otherwise, output a line containing the word IMPOSSIBLE.

假如输入

2
0
900
8
1400
1200
1000
800
600
400
200
0
0

应当输出

IMPOSSIBLE
POSSIBLE
be careful:读题一定要细致

#include<iostream>
#include<algorithm>
#include <vector>
#include<string.h>
#include<ctype.h>
using namespace std;
void fun();
int main()
{
	fun();
	return 0;
}
void fun()
{
	int i,n,arr[1500],flag;
	while(cin>>n&&n)
	{
		flag=1;
		for(i=0;i<n;i++)
			cin>>arr[i];
		sort(arr,arr+n,greater<int>());
		if(1422-arr[0]>100||arr[n-1]>100)//这是个大坑,是来回。所以需大于100不能到达
			flag=0;
		for(i=0;i<n&&flag;i++)
		{
			if(arr[i]-arr[i+1]>200)
			{
				flag=0;
				break;
			}
		}
		if(flag)
			cout<<"POSSIBLE"<<endl;
		else
			cout<<"IMPOSSIBLE"<<endl;
	}
}





转载于:https://www.cnblogs.com/ljbguanli/p/7286417.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值