2015
04-10

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. n lines 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.

The input contains several scenario. Each scenario begins with a line containing n, a positive number indicating the number of charging stations. n lines 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.

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

IMPOSSIBLE
POSSIBLE

#include <iostream>
using namespace std;
#include <cstdio>
#include <cstring>
#include <algorithm>
#define MAX 1500
int a[MAX], n;
int main(void)
{
while(scanf("%d", &n) && n)
{
int i, j;
a[0] = 0;
for(i = 1; i <= n; i++)
scanf("%d", &a[i]);
a[n+1] = 1422;
n = n + 2;
sort(a, a + n);
int flag = 0;
for(i = 0; i + 1 < n; i++)
{
if(a[i+1] - a[i] > 200)
flag = 1;
}
if(a[n - 1] - a[n-2] > 100) flag = 1;
if(flag == 1)
puts("IMPOSSIBLE");
else puts("POSSIBLE");
}
return 0;
}

1. 站长，你好！
你创办的的网站非常好，为我们学习算法练习编程提供了一个很好的平台，我想给你提个小建议，就是要能把每道题目的难度标出来就好了，这样我们学习起来会有一个循序渐进的过程！