首页 > ACM题库 > HDU-杭电 > HDU 4154-Alaska[解题报告]HOJ
2015
04-16

HDU 4154-Alaska[解题报告]HOJ

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<stdio.h>
#include<stdlib.h>
int f[1450]={0};
int main()
{
	int cmp(const void *a,const void *b);
	int t,i,max,p;
	while(scanf("%d",&t),t!=0)
	{
		max=0;
		p=0;
		for(i=0;i<t;i++)
		{
			scanf("%d",&f[i]);
		}
		qsort(f,t,sizeof(int),cmp);
		f[i]=1422;
		if((f[i]-f[i-1])>100)
		{
			printf("IMPOSSIBLE\n");
			p=1;
		}
		else
		{
			for(i=1;i<t;i++)
			{
				if((f[i]-f[i-1])>max)
				{
					max=f[i]-f[i-1];
					if(max>200)
					{
						p=1;
						break;
					}
				}
			}
			if(p==0)
			{
				printf("POSSIBLE\n");
			}
			else
			{
				printf("IMPOSSIBLE\n");
			}
		}
	}
	return 0;

}


int cmp(const void *a,const void *b)
{
	return *(int *)a-* (int*)b;
}

  1. 第一句可以忽略不计了吧。从第二句开始分析,说明这个花色下的所有牌都会在其它里面出现,那么还剩下♠️和♦️。第三句,可以排除2和7,因为在两种花色里有。现在是第四句,因为♠️还剩下多个,只有是♦️B才能知道答案。