Homework Introduction

#include <bits/stdc++.h>
using namespace std;
int n, m, k;
queue<int>q1, q2;

int main() {
	cin >> n >> m >> k;
	for (int i = 1; i <= n; i++)
		q1.push(i);
	for (int i = 1; i <= m; i++)
		q2.push(i);
	for (int i = 1; i <= k; i++) {
		cout << q1.front() << " " << q2.front() << endl;
		q1.push(q1.front());
		q1.pop();
		q2.push(q2.front());
		q2.pop();
	}
	return 0;
}
#include <bits/stdc++.h>
using namespace std;
const int N = 105;
int n, m, a[N];

struct node {
	int val, id;
};
queue<node>q;
priority_queue<int>pq;

int main() {
	cin >> n >> m;
	m++;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		q.push({a[i], i});
		pq.push(a[i]);
	}
	int tim = 0;
	while (!q.empty()) {
		if (q.front().val == pq.top()) {
			tim++;
			if (q.front().id == m) {
				cout << tim << endl;
				return 0;
			}
			q.pop();
			pq.pop();
		} else {
			q.push(q.front());
			q.pop();
		}
	}
	return 0;
}
#include <bits/stdc++.h>
using namespace std;
queue<int>q[1005], Q;
int n, m;
int book[100005];

int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		int x;
		cin >> x;
		for (int j = 1; j <= x; j++) {
			int t;
			cin >> t;
			book[t] = i;
		}
	}
	string s;
	while (cin >> s) {
		if (s == "STOP")
			break;
		if (s == "ENQUEUE") {
			int x;
			cin >> x;
			//编号为x的入队
			if (q[book[x]].size() != 0) {
				q[book[x]].push(x);
			} else if (q[book[x]].size() == 0) {
				q[book[x]].push(x);
				Q.push(book[x]);
			}
		} else if (s == "DEQUEUE") {
			//1.长队的堆首出队以后不为空
			if (q[Q.front()].size() > 1) {
				cout << q[Q.front()].front() << endl;
				q[Q.front()].pop();
			} else if (q[Q.front()].size() == 1) {
				cout << q[Q.front()].front() << endl;
				q[Q.front()].pop();
				Q.pop();
			}
		}
	}
	return 0;
}
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e5 + 5;

struct node {
	int v, t;
} a[N];
int n;

bool cmp(node a, node b) {
	if (a.t == b.t)
		return a.v > b.v;
	return a.t > b.t;
}

signed main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i].v >> a[i].t;
	}
	sort(a + 1, a + n + 1, cmp);
	int res = 0, ans = 0;
	priority_queue<int, vector<int>, greater<int> >q;
	for (int i = 1; i <= n; i++) {
		//a[i]能否出战?
		q.push(a[i].v);
		res += a[i].v;
		while (q.size() > a[i].t) {
			res -= q.top();
			q.pop();
		}
		ans = max(ans, res);
	}
	cout << ans << endl;
	return 0;
}
#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
int m, n, a[N], book[N];
queue<int>q;

int main() {
	cin >> m >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	int res = 0;
	for (int i = 1; i <= n; i++) {
		if (book[a[i]] == 0) {
			q.push(a[i]);
			book[a[i]] = 1;
			res++;
			if (q.size() > m) {
				book[q.front()] = 0;
				q.pop();
			}
		}
	}
	cout << res << endl;
	return 0;
}
#include <bits/stdc++.h>
using namespace std;
const int N = 105;
int n, m, a[N], b[N];

int main() {
	cin >> n >> m;
	queue<int>q;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		q.push(i);
	}
	int res = 0, ans;
	while (!q.empty()) {
		b[q.front()] += m;
		res += m;
		if (b[q.front()] >= a[q.front()]) {
			if (q.size() == 1) {
				ans = q.front();
			}
			q.pop();
		} else {
			q.push(q.front());
			q.pop();
		}
	}
	cout << ans << " " << res << endl;
	return 0;
}
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int n, k, a[N];
int q[N], tail = 1, head;

void push(int x) {
	q[++tail] = x;
}

int front() {
	return q[head];
}

void pop_back() {
	tail--;
}

void pop() {
	head++;
}

int empty() {
	return tail >= head;
}

int main() {
	cin >> n >> k;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	tail = -1, head = 0;
	for (int i = 1; i <= n; i++) {
		//判断a[i]何时入队
		while (tail >= head && a[i] <= a[q[tail]])
			--tail;
		q[++tail] = i;
		//判断队首是否符合要求
		while (tail >= head && i - q[head] + 1 > k)
			head++;
		if (i >= k)
			cout << a[q[head]] << " ";
	}
	cout << endl;
	tail = -1, head = 0;
	for (int i = 1; i <= n; i++) {
		while (tail >= head && a[i] >= a[q[tail]])
			tail--;
		q[++tail] = i;
		while (tail >= head && i - q[head] + 1 > k)
			head++;
		if (i >= k)
			cout << a[q[head]] << " ";
	}
	return 0;
}
#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 5;
int n, a[N], q[N], sum[N], tail = -1, head;

int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		a[i + n] = a[i];
	}
	for (int i = 1; i <= 2 * n; i++) {
		sum[i] = sum[i - 1] + a[i];
	}
	int res = 0;
	for (int i = 1; i < 2 * n; i++) {
		while (tail >= head && sum[i] <= sum[q[tail]])
			--tail;
		q[++tail] = i;
		while (tail >= head && i - q[head] + 1 > n)
			head++;
		if (i >= n && sum[q[head]] - sum[i - n] >= 0)
			res++;
	}
	cout << res << endl;
	return 0;
}
#include <bits/stdc++.h>
using namespace std;
const int N = 3e6 + 5;
int n, k, a[N];

struct node {
	int q[N], tail, head;
} qMax, qMin;

int main() {
	cin >> k >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	qMax.tail = -1, qMax.head = 0;
	qMin.tail = -1, qMin.head = 0;
	int l = 1, res = 0;
	for (int i = 1; i <= n; i++) {
		while (qMax.tail >= qMax.head && a[i] >= a[qMax.q[qMax.tail]])
			--qMax.tail;
		while (qMin.tail >= qMin.head && a[i] <= a[qMin.q[qMin.tail]])
			--qMin.tail;
		qMax.q[++qMax.tail] = i;
		qMin.q[++qMin.tail] = i;
		while (a[qMax.q[qMax.head]] - a[qMin.q[qMin.head]] > k) {
			if (qMax.q[qMax.head] < qMin.q[qMin.head]) {
				l = qMax.q[qMax.head] + 1;
				qMax.head++;
			} else {
				l = qMin.q[qMin.head] + 1;
				qMin.head++;
			}
		}
		res = max(res, i - l + 1);
	}
	cout << res << endl;
	return 0;
}
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
int n, k, a[N];
double b[N], sum[N], Pre[N];

int check(double x) {
	Pre[0] = 1e9;
	for (int i = 1; i <= n; i++) {
		b[i] = a[i] - x;
		sum[i] = sum[i - 1] + b[i];
		//sum[i]-sum[j] i-k+1>=j>=1
		Pre[i] = min(Pre[i - 1], sum[i]);
		if (i >= k && sum[i] - Pre[i - k] >= 0)
			return 1;
	}
	return 0;

}

int main() {
	cin >> n >> k;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	double l = 0, r = 1e6;
	while (r - l >= 1e-5) {
		double mid = (l + r) / 2;
		if (check(mid))
			l = mid;
		else
			r = mid;
	}
	cout << fixed << setprecision(5) << l << endl;
	return 0;
}
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e5 + 5;

struct node {
	int a, b, c, d;
	friend bool operator < (node a, node b) {
		if (a.a == b.a)
			return a.c < b.c;
		return a.a > b.a;
	}
} a[N];

struct Node {
	int a, b, c, d;
	friend bool operator < (Node a, Node b) {
		if (a.b == b.b)
			return a.d < b.d;
		return a.b > b.b;
	}
};
int n, T;
priority_queue<node>q, p;
priority_queue<Node>r;

signed main() {
	cin >> T;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i].a >> a[i].b >> a[i].c >> a[i].d;
		q.push(a[i]);
	}
	int first = 0, now = 0;
	while (!q.empty()) {
		if (now >= q.top().a) {
			now += q.top().c;
			p.push(q.top());
			q.pop();

		} else {
			first = q.top().a - now;
			now = q.top().a + q.top().c;
			p.push(q.top());
			q.pop();
		}
	}
	int nowa = first;
	int nowb = 0;
	int second = 0;
	while (!p.empty() || !r.empty()) {
		int cnt = 0;
		while (!p.empty() && nowa >= p.top().a) {
			cnt++;
			r.push((Node) {
				p.top().a, p.top().b, p.top().c, p.top().d
			});
			p.pop();
		}
		while (!r.empty() && nowb >= r.top().b) {
			nowa += r.top().c;
			nowb += r.top().d;
			r.pop();
		}
		if (cnt == 0 && !r.empty()) {
			second += r.top().b - nowb;
			nowb = r.top().b + r.top().d;
			nowa += r.top().c;
			r.pop();
		}
	}
	cout << first << " " << second << endl;
	return 0;
}
Status
Done
Problem
18
Open Since
2025-4-19 8:15
Deadline
2025-4-27 23:59
Extension
24 hour(s)