Educational Codeforces Round 112 (Rated for Div. 2)

Posted by SoundreameR on Mon, 03 Jan 2022 12:39:48 +0100

A,PizzaForces

Title Link: PizzaForces

Main idea of the title: it is required to order n pizzas. The available options are 6 pizzas / 15min, 8 pizzas / 20min and 10 pizzas / 25min. What is the minimum time required to get enough pizza.

Idea: we were stuck at the beginning. We can easily see that it takes 2.5 minutes for each pizza, so there is no difference in choosing different methods within a sufficient share, but in the selection of the last one, I choose module 6, and the remaining 0 is to choose all 6 pizzas / 15min. If the remaining 2 is less than 0, the last one will choose 8 pizzas / 20min, If you have less than 4 and more than 3, choose 10 pizzas / 20min. Of course, if n is less than, choose the first one.

code:

#include <iostream>
#include <algorithm>
using namespace std;
int main ()
{
	long long t, n, x, y;
	cin >> t;
	while(t--)
	{
		cin >> n;
		x = (n/6)*15;
		y = n%6;
		
		if (n <= 6)
		{
			cout << 15 << endl;
			continue;
		}
		
		if (y>=1&&y<=2)
		{
			x += 5;
		}
		else if (y>2&&y<=4)
		{
			x += 10;
		}
		else if(y==5)
		{
			x += 15;
		}
		cout << x << endl;
	}
	return 0;
}

B,Two Tables

Title Link: Two tables

First, we give you two positive integers W and h to determine the range of a rectangle in (0,0) and (W,H). Then we give you two coordinate points to determine a table and put it in the range of the rectangle. Finally, give you a length w width h in the space. If you can't put it down, output - 1. If you can, output the minimum distance to move the original table.

Topic idea: This is a very simple question. Let's think about whether we can put it down. At the same time, we can be sure that the original table will only move in one direction once, which is very easy to do. Directly try to move in all four directions, and take the minimum value if allowed.

Tucao: I don't know how to say it, I know how to do it, and the code is very short, but in the end I still make complaints about WA. Self closing. It seems that writing if and else by yourself still needs exercise, TAT.

code:

#include <iostream>
using namespace std;

int W, H, x1, x2, y1, y2, w, h, t;

int main ()
{
	cin >> t;
	while(t--)
	{
		cin >> W >> H >> x1 >> y1 >> x2 >> y2 >> w >> h;
		int ans = (int)1e9;
		if (x2 - x1 + w <= W)
		{
			ans = min(ans, max(0, w-x1));
			ans = min(ans, max(0, x2 - (W - w))); 
		}
		if (y2 - y1 + h <= H)
		{
			ans = min(ans, max(0, h-y1));
			ans = min(ans, max(0, y2 - (H - h)));
		}
		
		if (ans == (int)1e9)
		{
			cout << -1 << endl;
		}
		else
		{
			cout << ans << endl;
		}
	}
	return 0;	
} 

C,Coin Rows

Title Link: Coin Rows

Now there is a grid with two rows and N columns. Two people can only go down and right from (1,1) to (2,n). Each grid has different scores. As long as you guess the grid score, it belongs to the first person who steps on it. The final total score is the score obtained by the second person. The first person wants the second person's score to be as low as possible, And the second person asked himself to score as high as possible. Q. what is the final score for the best situation for both.

Topic idea: it is suggested to read this question three times, or read it only once (funny). I understood it correctly for the first time. When I understood it for the second time, I found that I couldn't understand this sentence: What will the score of the game be if both players play optimally? In fact, in the final analysis, the first person gets the maximum score, the second can get the maximum score, and finally output the score obtained by the second person. Returning to the topic, we found that each person can only go down once. Then, after the first person goes, the second person can only get all the remaining scores in the first line or all the remaining scores in the second line. As for why you can draw a picture, it should be easy to imagine. Finally, because it is a 1e5 query, we need to use the prefix and, which will appear later.

code:

#include <iostream>
using namespace std;

int t, n, a[200005], b[200005], c[200005], d[200005];

int main ()
{
	cin >> t;
	while(t--)
	{
		cin >> n;
		for(int i = 1; i <= n; i++)
		{
			cin >> a[i];
			b[i] = b[i-1] + a[i];
		}
		for(int i = 1; i <= n; i++)
		{
			cin >> c[i];
			d[i] = d[i-1] + c[i];
		}
		int ans = max(d[n], b[n]);
		for(int i = 1; i <= n; i++)
		{
			ans = min(ans, max(d[i-1], b[n] - b[i]));
		}
		cout << ans << endl;
	}
	return 0;	
} 

D,Say No to Palindromes

Title Link: Say No to Palindromes

A string of n length can only be composed of the first three letters of the alphabet (i.e. a, b and c), and then there are m queries. The interval of [l,r] can be changed at least (abc mutual conversion) several times before there is no palindrome string in this interval (palindrome string: aa, aba, aabb)

Topic idea: originally, it looked like a dp similar thing. Unexpectedly, it can be written with violence and prefix and. Mainly, there is a limitation because there are only three strings. We can find that all beautiful strings are the superposition of one of the abc full permutations. Therefore, we run out for each case and add it with prefix and, In the final query, the minimum value can be obtained from the six prefixes and answers of abc.

code:

#include <iostream>
#include <algorithm>
using namespace std;

string ss = "abc", s;
int num[6][200005], n, m, l, r;

int main ()
{
	int cnt = 0;
	cin >> n >> m >> s;
	do{
		for(int i = 0; i <= n; i++)
		{
			if (s[i] != ss[i%3])
			{
				num[cnt][i+1] = num[cnt][i] + 1;
			}
			else
			{
				num[cnt][i+1] = num[cnt][i];
			}
		}
		cnt++;
	}while(next_permutation(ss.begin(), ss.end()));
	
	while(m--)
	{
		int ans = n;
		cin >> l >> r;
		for(int i = 0; i < 6; i++)
		{
			ans = min(ans, num[i][r] - num[i][l-1]);
		}
		cout << ans << endl;
	}
	return 0;
}

Topics: Algorithm