比赛 ctime蒟蒻生日赛 评测结果 AAAAAAAAAA
题目名称 过河 最终得分 100
用户昵称 胡嘉兴 运行时间 0.105 s
代码语言 C++ 内存使用 2.48 MiB
提交时间 2017-10-17 15:08:54
显示代码纯文本
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;

#define N 100 + 7
#define M 1000000 + 7

int w[N] = {0}, f[M] = {0};
int min(int a, int b)
{
	if(a < b)
	{
		return a;
	}
	return b;
}
int gcd(int a, int b)
{
	return b == 0 ? a : gcd(b, a % b);
}
void qsort(int left, int right)
{
	int i = left, j = right, t, temp = w[left];
	if(i >= j)
	{
		return;
	}
	while(i < j)
	{
		while(i < j&&w[j] >= temp)
		{
			j--;
		}
		while(i < j&&w[i] <= temp)
		{
			i++;
		}
		t = w[i];
		w[i] = w[j];
		w[j] = t;
	}
	t = w[i];
	w[i] = w[left];
	w[left] = t;
	qsort(left, i - 1);
	qsort(i + 1, right);
	return;
}
int main()
{
	int l, s, t, m, lcm = 1, k = 1, book = 1, a;
	freopen("river.in", "r", stdin);
	freopen("river.out", "w", stdout);
	
	scanf("%d%d%d%d", &l, &s, &t, &m);
	
	for(int i = 1; i <= m; i++)
	{
		
		scanf("%d", &w[i]);
		
	}
	m++;
	w[m] = l;
	qsort(1, m);
	for(int i = s; i <= t; i++)
	{
		lcm = i * lcm / gcd(i, lcm);
	}
	f[0] = 0;
	a = w[1];
	if(a > 10 * t)
	{
		a %= 10 * t;
		a += t;
	}
	f[a] = 1;
	k = a + 1;
	for(int i = 2; i <= m; i++)
	{
		int b = w[i] - w[i - 1] - 1;
		if(b > 20 * t)
		{
			b %= 10 * t;
		}
		k += b;
		if(i != m)
		{
			f[k++] = 1;
		}
		else
		{
			f[k++] = 0;
		}
	}
	for(int i = 1; i < s; i++)
	{
		if(f[i] == 0)
		{
			f[i] = -99999999;
		}
	}
	for(int i = s; i < k; i++)
	{
		int c = 99999999, flag = 1;
		for(int j = s; j <= t; j++)
		{
			if(f[i - j] < 0)
			{
				continue;
			}
			c = min(f[i - j], c);
			flag = 0;
		}
		if(flag)
		{
			f[i] = -99999999;
		}
		else
		{
			f[i] += c;
		}
	}

	for(int i = k - 1; book; i--)
	{
		if(f[i] >= 0)
		{
			
			printf("%d\n", f[i]);
			
			book = 0;
		}
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}