WA on #5,感觉判了如果后面没有油价更低的站
查看原帖
WA on #5,感觉判了如果后面没有油价更低的站
902351
Little_x_starTYJ楼主2025/2/5 19:49

rt。

using namespace std;
struct node {
	double d, p;
	inline bool operator < (const node t) const {
		return d < t.d;
	}
} a[10];
signed main() {
	ios::sync_with_stdio(false);
	ios_base::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	double D1, C, D2, P;
	int n;
	cin >> D1 >> C >> D2 >> P >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i].d >> a[i].p;
	}
	a[++n].d = 0;
	a[n].p = P;
	sort(a + 1, a + 1 + n);
	double ans = 0, nowc = 0;
	for (int i = 1; i <= n; ) {
		double distance = C * D2 + a[i].d, money = 114514;
		int id = i, id2 = i;
		for (int j = i + 1; j <= n; j++) {
			if (a[j].d > distance) {
				break;
			}
			if (a[j].p < money) {
				money = a[j].p;
				id2 = j;
			}
			if (a[j].p < a[i].p && id == i) {
				id = j;
			}
		}
		if (id2 == i && distance < D1) {
			cout << "No Solution";
			return 0;
		}
		if (i == n || id == i && distance >= D1) {
			ans += (D1 - a[i].d) / D2 * a[i].p;
			break;
		}
		if (id == i) {
			ans += (C - nowc) * a[i].p;
			nowc = C - (a[id2].d - a[i].d) / D2;
			i = id2;
		} else {
			double oil = (a[id].d - a[i].d - nowc * D2) / D2;
			ans += oil * a[i].p;
			i = id;
			nowc = 0;
		}
		
	}
	printf("%.2lf", ans);
	return 0;
}
2025/2/5 19:49
加载中...