1095. Cars on Campus (30)

#include <iostream>
#include <string>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

struct node
{
	int flag, time, index;
};

vector<node> v[10010];
char carname[10010][10];

int cmp1(node n1, node n2)
{
	return n1.time < n2.time;
}

int cmp2(int a, int b)
{
	return strcmp(carname[a], carname[b]) < 0;
}

int main()
{
	int n, k;
	scanf("%d%d", &n, &k);

	map<string, int> si;
	map<string, int> ::iterator it;

	int i, hour, minute, second, index = 1, curindex;
	char curcarname[10], status[5];
	node nod;

	for(i = 1; i <= n; i++)
	{
		getchar();
		scanf("%s%d:%d:%d%s", curcarname, &hour, &minute, &second, status);

		it = si.find(curcarname);
		if(it == si.end())
		{
			si[curcarname] = curindex = index++;
		}
		else
		{
			curindex = it->second;
		}

		nod.index = curindex;
		strcpy(carname[curindex], curcarname);

		if(status[0] == 'i')
		{
			nod.flag = 1;
		}
		else
		{
			nod.flag = 0;
		}

		nod.time = hour * 3600 + minute * 60 + second;
		v[curindex].push_back(nod);
	}

	int j, size, parktime, maxparktime = 0;
	node curnode, nextnode;

	vector<int> res;
	vector<node> car;

	for(i = 1; i < index; i++)
	{
		sort(v[i].begin(), v[i].end(), cmp1);

		size = v[i].size();
		parktime = 0;

		for(j = 0; j < size; j++)
		{
			curnode = v[i][j];
			if(curnode.flag == 1 && j + 1 < size && v[i][j + 1].flag == 0)
			{
				nextnode = v[i][j + 1];
				parktime += nextnode.time - curnode.time;

				car.push_back(curnode);
				car.push_back(nextnode);
			}
		}

		if(parktime > maxparktime)
		{
			maxparktime = parktime;

			res.clear();
			res.push_back(i);
		}
		else if(parktime == maxparktime)
		{
			res.push_back(i);
		}
	}

	sort(car.begin(), car.end(), cmp1);

	int curtime, count = 0;
	size = car.size();
	j = 0;

	for(i = 1; i <= k; i++)
	{
		scanf("%d:%d:%d", &hour, &minute, &second);
		curtime = hour * 3600 + minute * 60 + second;

		while(j < size)
		{
			curnode = car[j];
			if(curnode.time > curtime)
			{
				break;
			}

			if(curnode.flag == 1)
			{
				count++;
			}
			else
			{
				count--;
			}

			j++;
		}

		printf("%d\n", count);
	}

	sort(res.begin(), res.end(), cmp2);

	size = res.size();
	for(i = 0; i < size; i++)
	{
		if(i > 0)
		{
			printf(" ");
		}

		printf("%s", carname[res[i]]);
	}

	hour = maxparktime / 3600;
	minute = (maxparktime - hour * 3600) / 60;
	second = maxparktime % 60;

	printf(" %02d:%02d:%02d\n", hour, minute, second);

	system("pause");
	return 0;
}

 

posted on 2025-11-23 17:23  王景迁  阅读(4)  评论(0)    收藏  举报

导航