2021.08. 09 [popularization group] simulation group C competition summary

Posted by crosbystillsnas on Sun, 26 Dec 2021 17:48:26 +0100

2021.08. 09 [popularization group] simulation group C competition summary

Write before:

Today's exam is average. I didn't do very well. Continue to work hard next time! 😢😢😢

The mistake of this competition is that I didn't seriously read the meaning of the topic. Next time, I will continue to work hard!

ok, let's start summarizing!

T1: [popularization simulation] production of weapons

Main idea of the title:

Recently, he flew across the sea and finally made a desertion at oi headquarters. Now he has been transferred to oi Defense Department to make tools against Kidd. Of course, these tasks are carried out on the machines in OI headquarters, but Feihai has never had such experience. Now Feihai has received a number of new tasks. Now he wants to program to control the machines. It is known that the machine works n minutes a day. When flying over the sea and pressing the start button, the machine starts to run. At present, the general manager of OI has given K production targets, but there is only one machine, Therefore, the general manager wants to know how many parts the machine can produce at least (that is, how many minutes it can work). If there are many parts to be processed at the same time, the machine can only select one. However, there is a time limit for a part task, that is, one part must start from P and last for T minutes (what a far fetched rule!). Because flying across the sea is very busy, please write this program!

Positive solution:

???

Therefore, the chief secretary wants to know how many parts the machine can produce at least (that is, how many minutes it can work at least). What does it mean??? Where and where???

People are stupid jpg

It's just a sort + DP. We use f i f_i fi , to indicate from time to time i i i. Until the moment n n N, in this period of time, he can steal the most laziness. Let's use the starting point to sort and steal some laziness in enumerating 1 to n moments!

Unfortunately, I only want to mess around in the exam

AC, PA, it's gone

code:

#include <bits/stdc++.h>
#define fre(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)

using namespace std;

const int N = 10000001;
int a[N];
int b[N];
int f[N];
int x, ans;

void qsort(int left, int right) {
	int i = left, j = right;
	int mid = a[(i+j)/2];
	while (i <= j) {
		while (a[i] < mid) i ++;
		while (a[j] > mid) j --;
		if (i <= j) {
			swap(b[i], b[j]);
			swap(a[i], a[j]);
			i++; j--;
		}
	}
	if (i < right) qsort(i, right);
	if (j > left) qsort(left, j);
}

int main() {
	fre(produce);
	int n, k;
	scanf ("%d%d", &n, &k);
	for (int i = 1; i <= k; i ++) {
		scanf ("%d%d", &a[i], &b[i]);
	}
	qsort(1, k);
	for (int i = n; i >= 1; i --) {
		if (i != a[k]) f[i] = f[i + 1] + 1;
		else {
			while (k && i == a[k]) {
				f[i] = max(f[i], f[i+b[k]]);
				k --;
			}
		}
	}
	printf ("%d", n - f[1]);
	return 0;
}

T2: [universal simulation] Urban connection

Main idea of the title:

The network of heaven is broad, careless but not leaky. After the last arrest, OI headquarters finally obtained the characteristics of strange thieves! Now, we need to send Kidd's characteristics to super Daniel before he comes again. Unfortunately, super Daniel is not in the headquarters, so we must send the data to Daniel's house as soon as possible when flying across the sea. It is known that there are n-2 cities between oi headquarters and Daniu's house. In order to reach the destination as soon as possible, fly across the sea and learn the route map from oi headquarters to Daniu's house through the crystal ball, which shows the connection distance between n cities. But flying across the sea is very busy. I need you to help write a program.

Positive solution:

In fact, the difficulty of this problem is not much different from that of this problem, but

"Roadmap", "get to your destination as soon as possible", "connection distance"

It's... the shortest way naked. It's too water!

We are defining a similar union search set f a t h e r i father_i fatheri array to represent link points i i i , is that point. We just need to use it to find points i i The relaxation point v of i is assigned to f a t h e r i father_i fatheri #

Then we find the complete graph and output it. Note that we must check it!!! (lesson of blood)

SPFA forever god!!!

code:

#include <bits/stdc++.h>
#define fre(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)

using namespace std;

const int N = 200001;
const int M = 1001;
const int MAX = 1e9*2;

int a[M][M];
int dis[M];
int answer[M];
bool vis[N];
int n;
int q[N];

void find(int i) {
	if (answer[i] != 0) {
		find(answer[i]);
	}
	printf ("%d ", i);
}

void spfa(int s) {
	for (int i = 1; i <= n; i ++) {
		dis[i] = MAX;
		vis[i] = false;
	}
	dis[s] = 0;
	vis[s] = true;
	int begin = 0, end = 1;
	q[1] = s;
	while (begin <= end) {
		int v = q[++begin];
		vis[v] = false;
		for (int i = 1; i <= n; i ++) {
			if (dis[i] > dis[v] + a[v][i] && a[v][i] != 0) {
				dis[i] = dis[v] + a[v][i];
				answer[i] = v;
				if (vis[i] == false) {
					vis[i] = true;
					q[++end] = i;
				}
			}
		}
	}
}

int main() {
	fre(city);
	scanf ("%d", &n);
	for (int i = 1; i <= n; i ++)
		for (int j = 1; j <= n; j ++) {
			int x;
			scanf("%d", &x);
			a[i][j] = x;
		}
	spfa(1);
	find(n);
	printf ("\n%d", dis[n]);
}

T3: [popularization simulation] rescue document

Main idea of the title:

Now, there is a strange thief in OI, that is Kidd! He once stole the famous Paris Sunshine, which shocked you! Therefore, after that, many big cattle forgot to eat and sleep and studied effective ways to deal with Kidd. During this period, in order to prevent Kidd from stealing again, OI commander-in-chief decided to send OIER to protect oi headquarters. Now that you are the captain of the OI defense team, you need to arrange as many oi special traps as possible in the OI headquarters! Originally, the OI headquarters was completely separated, and special pipelines were needed to reach the OI headquarters. Now, in order to protect the headquarters, OIER has designed many traps to let Kidd fall into the net.
Now there is a valuable planning information provided by super invincible Daniel, which needs to be deployed by you. Your task is to write a program to realize this plan.

Positive solution:

This question

What a smelly problem! 🤮🤮🤮 (annoyed)

Human translation:

Please find the longest non descending subsequence, pro 😙.

🤬🤬🤬

We first use the left endpoint to sort, and then use the right endpoint to find the longest non descending subsequence.

Or that sentence: what a smelly problem! 🤮🤮🤮 (annoyed)

code:

#include <bits/stdc++.h>
#define fre(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)

using namespace std;

const int N = 500001;

struct track {
	int x;
	int y;
}a[N];

int f[N], myd, n;
int maxn=0;

int pd(track x, track y) {
	return x.x < y.x ;
}

int main() {
	fre(save);
	scanf ("%d%d%d", &myd, &myd, &n);
	for (int i = 1; i <= n; i ++) {
		scanf("%d %d", &a[i].x, &a[i].y);
	}
	sort(a + 1, a + n + 1, pd);
	f[1] = 1;
	for (int i = 1; i <= n ; i ++) {
		for (int j = 0; j < i; j ++) {
			if (a[i].y > a[j].y) {
				f[i] = max(f[j] + 1, f[i]);
				maxn = max(maxn, f[i]);
			}
		}
	}
	printf ("%d", maxn);
	return 0;
}

T4: [popular simulation] confidential document

Main idea of the title:

Oi headquarters has recently received reliable information, In recent days, strange thief Kidd will come to oi headquarters again to steal confidential documents (because they are confidential, they cannot be disclosed), so OIER has to back up the documents before strange thief Kidd comes. However, today, OI headquarters has a power outage, so it has to be copied manually. Now, there are M materials and K oiers in OI headquarters (S) , you need to back up each copy of data. The number of pages of M copies of data is not necessarily the same (there are different and the same).

Now, as one of the oiers, you allocate the data to the OIER for backup. Because there are too many people, the data allocated by each OIER must be in continuous order, and the backup speed of each OIER is the same.

Your task is to minimize the backup time and list the shortest solutions. There may be multiple solutions to the data, so when there are multiple solutions, let the people in front backup less.

Positive solution:

When I look at this question, my backhand is greedy...

This is a bit like a candle. We use the two-point answer to find out the time spent, and then add a special judgment when calculating the interval. Pay attention to the situation that you just count one paragraph at a time (because you always have to have less people who are the first to do it). Don't let the number of segments be greater than the number of books.

Or that sentence: what a smelly problem! 🤮🤮🤮 (annoyed)

code:

#include <bits/stdc++.h>
#define fre(x) freopen(#x".in","r",stdin), freopen(#x".out","w",stdout)

using namespace std;

const int N=1001;

int m,k,a[N],l,r,sum[N][2],tot;

bool check(int t) {
	int ans = 0,num = 1;
	for (int i = 1; i <= m; i ++) {
		ans += a[i];
		if (ans > t) {
			num ++;
			ans = a[i];
		}
	}
	return num > k;
}

int main() {
	fre(secret);
	scanf ("%d%d",&m,&k);
	for (int i = 1; i <= m; i ++) {
		scanf ("%d", &a[i]);
		l = max(l, a[i]);
		r += a[i];
	}
	while (l < r) {
		int mid = l + r >> 1;
		if (check(mid)) l = mid + 1;
		else r=mid;
	}
	int d = 0; 
	sum[0][0] = m + 1;
	for (int i = m; i >= 1; i --) {
		d += a[i];
		if (d > l) {
			tot ++;
			sum[tot][0] = i + 1;
			sum[tot][1] = sum[tot - 1][0] - 1;
			d = a[i];
			continue;
		}
		if (i == k - tot and i != 1) {
			tot++;
			sum[tot][0] = i;
			sum[tot][1] = sum[tot-1][0]-1;
			d=0;
		}
	}
	sum[k][0] = 1;
	sum[k][1] = sum[k-1][0]-1;
	for (int i = k; i >= 1; i --)
		printf ("%d %d\n", sum[i][0], sum[i][1]);
	return 0;
}

Write at the end:

In the future exams, we should seriously do questions and strive to get a good result!

come on.

Topics: C++ Algorithm Dynamic Programming greedy algorithm