2020 ICPC上海站 D Walker

2020 ICPC上海站 D Walker

题目链接:https://ac.nowcoder.com/acm/contest/9925/D

题目大意

给你一个线段的长度\(n\)和两个人,他们的速度是\(v1,v2\)他们的坐标是\(p1,p2\),他们在线段上跑,求跑完整个线段的最短时间。

思路

坤子哥直接推出了方程=.= TQL

我是考虑分成四种情况:

1.第一个人走完全程

2.第二个人走完全程

3.两个人一起向中间走,一直走到另一头

4.将线段分成线段a和线段b两部分,左边的人负责走线段a,右边的人负责走线段b

显然前三种情况可以直接计算出来,而最后一种情况我们可以通过枚举分割点x来计算。

\(f(x)\)为当分割点为x时走完全部线段的最短时间,并且很显然地,\(f(x)\)是个凹形的二次函数,那么我们就可以用三分来求最值。

关于三分的讲解看这里

Code

#include<string>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<vector>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
#define LL long long
#define MOD 100000007
#define PI 3.1415926535898
#define INF 0x3f3f3f3f
#define MAXN 200050
#define register long long
const double EPS = 1e-8;
LL read()
{
	LL w = 1, x = 0;
	char ch = 0;
	while (ch < '0' || ch>'9')
	{
		if (ch == '-')
			w = -1;
		ch = getchar();
	}
	while (ch >= '0' && ch <= '9')
	{
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	return w * x;
}
map<string, int >mp;
int t, m, n;
string s[105], ss;
int main()
{
	t = read();
	while (t--)
	{
		n = read();
		m = read();
		mp.clear();
		ss = "";
		for (register int i = 1; i <= n + m; i++)
			cin >> s[i];
		for (register int i = n + 1; i <= n + m; i++)
		{
			ss = "";
			for (register int j = 0; j <= s[i].length(); j++)
			{
				ss += s[i][j];
				if (s[i][j] == '/')
				{
					mp[ss] = 1;
					//continue;
				}

			}
		}
		int ans = n;
		ss = "";
		for (register int i = 1; i <= n; i++)
		{
			ss = "";
			for (register int j = 0; j < s[i].length(); j++)
			{

				ss += s[i][j];
				if (s[i][j] == '/')
				{
					if (mp[ss] == 0)
					{
						mp[ss] = 2;
					}
					else
					{
						if (mp[ss] == 1)
						{
							continue;
						}
						else
						{
							ans--;
							break;
						}
					}
				}
			}
		}
		cout << ans << endl;
		for (register int i = 1; i <= n + m; i++)
		{
			s[i] = "";
		}
	}
	return 0;
}
posted @ 2021-01-06 19:09  陆明燃  阅读(175)  评论(0)    收藏  举报