pku2674.cpp

来自「这是ACM 方面的资料 是PKU的 北京大学的出来的」· C++ 代码 · 共 76 行

CPP
76
字号
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

typedef struct Node
{
	double pos;
	int dir;
	char name[300];
}Node;

bool cmp(const Node &a, const Node &b)
{
	return a.pos < b.pos;
}

const int maxn = 33000;
int N;
double L, V;
int pcnt, ncnt;
Node x[maxn];

void Solve()
{
	int i, maxdir = 0, bestpos;
	double maxt = 0, tmpt, best;
	char tmp_s[3];
	scanf("%lf %lf", &L, &V);
	pcnt = 0;
	ncnt = 0;
	for (i = 0; i < N; i++)
	{
		scanf("%s %lf %s", tmp_s, &x[i].pos, x[i].name);
		if (tmp_s[0] == 'p' || tmp_s[0] == 'P')
		{
			x[i].dir = 1;
			tmpt = (L - x[i].pos) / V;
			pcnt++;
			if (tmpt > maxt)
			{
				maxt = tmpt;
				maxdir = 1;
			}
		}
		else
		{
			x[i].dir = 0;
			tmpt = x[i].pos / V;
			ncnt++;
			if (tmpt > maxt)
			{
				maxt = tmpt;
				maxdir = -1;
			}
		}
	}
	printf("%10d.%02d ", (int)(maxt * 100) / 100, (int)(maxt * 100) % 100);
	sort(x, x + N, cmp);
	if (maxdir == -1)
	{
		printf("%s\n", x[ncnt - 1].name);
	}
	else
	{
		printf("%s\n", x[ncnt].name);
	}
}
int main()
{
	while (EOF != scanf("%d", &N) && N)
		Solve();
	return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?