HDU OJ 4505 小Q系列故事——电梯里的爱情

#include <stdio.h>

int max(int a[100], int n)	//求最高层数
{
	int highest;
	int i;

	highest = a[0];

	for (i = 1; i < n; i++)
	{
		if (a[i] > highest)
			highest = a[i];
	}

	return highest;
}

int count_time(int n, int a[100], int highest)//计算每组测试需要的总时间
{
	int i, j;
	int flag;		//标记每层是否有人下
	int time;

	time = 0;
	for (i = 0; i <= highest; i++)	//计算每层花费时间
	{
		time += 6;
		flag = 0;
		for (j = 0; j < n; j++)		//计算每层每个人花费的时间
		{
			if (a[j] == i)
			{
				time += 1;
				flag = 1;
			}
		}
		if (flag)					//每层的开门时间
			time += 5;		
	}

	time += highest * 4;			//电梯下楼花费时间

	return time;
}

int main()
{
	int c, n, a[100], time;
	int i;
	int highest;	//要到的最高层

	scanf("%d", &c);

	while (c != 0)
	{
		time = 0;

		scanf("%d", &n);
		for (i = 0; i < n; i++)		//记录每个人要到的层数到a[i]
		{
			scanf("%d", &a[i]);
		}

		highest = max(a, n);

		time = count_time(n, a, highest);	//计算每组测试需要的总时间
		
		printf("%d\n", time-6);

		c--;
	}

	return 0;
}

 

本文章迁移自http://blog.csdn.net/timberwolf_2012/article/details/8743678

/** * RECOMMENDED CONFIGURATION VARIABLES: EDIT AND UNCOMMENT THE SECTION BELOW TO INSERT DYNAMIC VALUES FROM YOUR PLATFORM OR CMS. * LEARN WHY DEFINING THESE VARIABLES IS IMPORTANT: https://disqus.com/admin/universalcode/#configuration-variables*/ /* var disqus_config = function () { this.page.url = PAGE_URL; // Replace PAGE_URL with your page's canonical URL variable this.page.identifier = PAGE_IDENTIFIER; // Replace PAGE_IDENTIFIER with your page's unique identifier variable }; */ (function() { // DON'T EDIT BELOW THIS LINE var d = document, s = d.createElement('script'); s.src = 'https://chenzz.disqus.com/embed.js'; s.setAttribute('data-timestamp', +new Date()); (d.head || d.body).appendChild(s); })();