☺☺☺☺☺☺☺☺☺☺☺☺☺☺☺☺  •  1年前


#include <bits/stdc++.h>
using namespace std;
int s[1000005], v[1000005], q[1000005];

int main() {
	int n, d;
	cin >> n >> d;
	s[1] = 0;
	for (int i = 2; i <= n; i++) {
		int t;
		cin >> t;
		s[i] = t + s[i - 1];
	}
	for (int i = 1; i <= n; i++) {
		cin >> v[i];
	}
	int cnt = 1;
	q[1] = 1;
	for (int i = 2; i <= n; i++) {
		if (v[i] < v[q[cnt]]) {
			cnt++;
			q[cnt] = i;
		}
	}
	if (q[cnt] = n) {
		q[cnt++] = n;
	}
	int ans = 0, now = 0;
	for (int i = 1; i < cnt; i++) {
		int t = s[q[i + 1]] - s[q[i]];
		if (t < now) {
			now -= t;
		} else {
			t -= now;
			int tep = (t + d - 1) / d;
			ans += tep * v[q[i]];
			now = tep * d - t;
		}
	}
	cout << ans;
	return 0;
}

评论:

#include <bits/stdc++.h>
using namespace std;

int f(int n) {
	if (n % 3 == 1) {
		return 1;
	}
	return f(n - (n + 2 ) / 3) + 1;
}

int main() {
	long long int n;
	long long int ans = 0, flag = 0, t, y = 1;
	cin >> n;
	int m = n;
	while (m) {
		m -= (m + 2) / 3;
		ans++;
	}
	cout << ans << " " << f(n);
	return 0;
}

☺☺☺☺☺☺☺☺☺☺☺☺☺☺☺☺  •  1年前

请先登录,才能进行评论