Educational Codeforces Round 91 (Rated for Div. 2) 题解报告

A - Three Indices CodeForces - 1380A

You are given a permutation p1,p2,…,pn. Recall that sequence of n integers is called a permutation if it contains all integers from 1 to n exactly once.

Find three indices i, j and k such that:

1≤i<j<k≤n;
pipk.
Or say that there are no such indices.
Input
The first line contains a single integer T (1≤T≤200) — the number of test cases.

Next 2T lines contain test cases — two lines per test case. The first line of each test case contains the single integer n (3≤n≤1000) — the length of the permutation p.

The second line contains n integers p1,p2,…,pn (1≤pi≤n; pi≠pj if i≠j) — the permutation p.

Output
For each test case:

if there are such indices i, j and k, print YES (case insensitive) and the indices themselves;
if there are no such indices, print NO (case insensitive).
If there are multiple valid triples of indices, print any of them.

Example
Input
3
4
2 1 4 3
6
4 6 1 2 5 3
5
5 3 1 2 4
Output
YES
2 3 4
YES
3 5 6
NO
题意:找到有没有能满足这个式子的
1≤i<j<k≤n;
pipk.

思路:就是水题。。。

#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<string>
#include<iomanip>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
typedef long long ll;
int main()
{
	int t; cin >> t;
	while (t--)
	{
		int n; cin >> n;
		int a[1001];
		int b[1001];
		for (int i = 1; i <= n; i++)
		{
			cin >> a[i];
			b[a[i]] = i;
		}
		int f = 0;
		for (int i = 2; i < n; i++)
		{
			if (a[i] > a[i - 1] && a[i] > a[i + 1])
			{
				cout << "YES" << endl;
				f = 1;
				cout <<b[a[i-1]]<< " " <<b[a[i]] << " " << b[a[i + 1]] << endl;
				break;
			}
		}
		if (f == 0)
			cout << "NO" << endl;
	}
}

B - Universal Solution CodeForces - 1380B

Recently, you found a bot to play “Rock paper scissors” with. Unfortunately, the bot uses quite a simple algorithm to play: he has a string s=s1s2…sn of length n where each letter is either R, S or P.

While initializing, the bot is choosing a starting index pos (1≤pos≤n), and then it can play any number of rounds. In the first round, he chooses “Rock”, “Scissors” or “Paper” based on the value of spos:

if spos is equal to R the bot chooses “Rock”;
if spos is equal to S the bot chooses “Scissors”;
if spos is equal to P the bot chooses “Paper”;
In the second round, the bot’s choice is based on the value of spos+1. In the third round — on spos+2 and so on. After sn the bot returns to s1 and continues his game.

You plan to play n rounds and you’ve already figured out the string s but still don’t know what is the starting index pos. But since the bot’s tactic is so boring, you’ve decided to find n choices to each round to maximize the average number of wins.

In other words, let’s suggest your choices are c1c2…cn and if the bot starts from index pos then you’ll win in win(pos) rounds. Find c1c2…cn such that win(1)+win(2)+⋯+win(n)n is maximum possible.

Input
The first line contains a single integer t (1≤t≤1000) — the number of test cases.

Next t lines contain test cases — one per line. The first and only line of each test case contains string s=s1s2…sn (1≤n≤2⋅105; si∈{R,S,P}) — the string of the bot.

It’s guaranteed that the total length of all strings in one test doesn’t exceed 2⋅105.

Output
For each test case, print n choices c1c2…cn to maximize the average number of wins. Print them in the same manner as the string s.

If there are multiple optimal answers, print any of them.

Example
Input
3
RRRR
RSP
S
Output
PPPP
RSP
R
Note
In the first test case, the bot (wherever it starts) will always choose “Rock”, so we can always choose “Paper”. So, in any case, we will win all n=4 rounds, so the average is also equal to 4.

In the second test case:

if bot will start from pos=1, then (s1,c1) is draw, (s2,c2) is draw and (s3,c3) is draw, so win(1)=0;
if bot will start from pos=2, then (s2,c1) is win, (s3,c2) is win and (s1,c3) is win, so win(2)=3;
if bot will start from pos=3, then (s3,c1) is lose, (s1,c2) is lose and (s2,c3) is lose, so win(3)=0;
The average is equal to 0+3+03=1 and it can be proven that it’s the maximum possible average.
A picture from Wikipedia explaining “Rock paper scissors” game:

题意:就是给你一串字符那些字符都是 R P S组成分别都是 石头 布剪刀,问你最大的平均胜利是多少,让你给出这个应对的串,计算的时候起点不一样,这样来算胜利的。
思路:自己就是了一下,要不就是 对应的全都是我赢,但这个wr了,我又去试了下全都输出最多的字符的相反字符,就可以了/

#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<string>
#include<iomanip>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
typedef long long ll;
char s[200001], c[200001];
int main()
{
	int t; cin >> t;
	while (t--)
	{
		
		cin >> s; int n = strlen(s);
		int pp = 0, ss = 0, rr = 0;
		for (int i = 0; i<n; i++)
		{
			if (s[i] == 'P')
				ss++;
			if (s[i] == 'S')
				rr++;
			if (s[i] == 'R')
				pp++;
		}
		if (ss >= rr && ss >= pp)
		{
			for (int i = 0; i < n; i++)
				cout << "S";
		}
		else if (rr >=ss &&rr >= pp)
		{
			for (int i = 0; i < n; i++)
				cout << "R";
		}
		else if (pp >= rr && pp >= ss)
		{
			for (int i = 0; i < n; i++)
				cout << "P";
		}
		cout << endl;
		
	}
}

C - Create The Teams CodeForces - 1380C

There are n programmers that you want to split into several non-empty teams. The skill of the i-th programmer is ai. You want to assemble the maximum number of teams from them. There is a restriction for each team: the number of programmers in the team multiplied by the minimum skill among all programmers in the team must be at least x.

Each programmer should belong to at most one team. Some programmers may be left without a team.

Calculate the maximum number of teams that you can assemble.

Input
The first line contains the integer t (1≤t≤1000) — the number of test cases.

The first line of each test case contains two integers n and x (1≤n≤105;1≤x≤109) — the number of programmers and the restriction of team skill respectively.

The second line of each test case contains n integers a1,a2,…,an (1≤ai≤109), where ai is the skill of the i-th programmer.

The sum of n over all inputs does not exceed 105.

Output
For each test case print one integer — the maximum number of teams that you can assemble.

Example
Input
3
5 10
7 11 2 9 5
4 8
2 4 2 3
4 11
1 3 3 7
Output
2
1
0
题意:分组,给你人数和x,看一个组成不成立,就是看 人数×组内min(a[i])>=x.问你最多分几组
思路:肯定从最大的开始算就可以,然后往前推,每次就算x/a[i];看看前面有这么多人吗。

#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<string>
#include<iomanip>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
typedef long long ll;
ll a[100005], v[100005];
int main()
{
	int t; cin >> t;
	while (t--)
	{
		ll n, x; cin >> n >> x;
		for (ll i = 1; i <= n; i++)
			cin >> a[i];
		sort(a + 1, a + 1 + n);
		ll ans = 0;
		ll shang = n+1;
		for (ll i = n; i >= 1; i--)
		{
			int b;
			if (x % a[i] == 0)
				b = x / a[i];
			else b = x / a[i] + 1;
			if (shang-i>=b)
			{
				ans++;
				shang = i;
			}
		}
		cout << ans << endl;
	}
}

D - Berserk And Fireball CodeForces - 1380D

There are n warriors in a row. The power of the i-th warrior is ai. All powers are pairwise distinct.

You have two types of spells which you may cast:

Fireball: you spend x mana and destroy exactly k consecutive warriors;
Berserk: you spend y mana, choose two consecutive warriors and the warrior with greater power destroys another chosen warrior.
For example, let the powers of warriors be [2,3,7,8,11,5,4], and k=3. If you cast Berserk on warriors with powers 8 and 11, the resulting sequence of powers becomes [2,3,7,11,5,4]. Then, for example, if you cast Fireball on consecutive warriors with powers [7,11,5], the resulting sequence of powers becomes [2,3,4].

You want to turn the current sequence of warriors powers a1,a2,…,an into b1,b2,…,bm. Calculate the minimum amount of mana you need to spend on it.

Input
The first line contains two integers n and m (1≤n,m≤2⋅105) — the length of sequence a and the length of sequence b respectively.

The second line contains three integers x,k,y (1≤x,y,≤109;1≤k≤n) — the cost of fireball, the range of fireball and the cost of berserk respectively.

The third line contains n integers a1,a2,…,an (1≤ai≤n). It is guaranteed that all integers ai are pairwise distinct.

The fourth line contains m integers b1,b2,…,bm (1≤bi≤n). It is guaranteed that all integers bi are pairwise distinct.

Output
Print the minimum amount of mana for turning the sequnce a1,a2,…,an into b1,b2,…,bm, or −1 if it is impossible.

Examples
Input
5 2
5 2 3
3 1 4 5 2
3 5
Output
8
Input
4 4
5 1 4
4 3 1 2
2 4 3 1
Output
-1
Input
4 4
2 1 11
1 3 2 4
1 3 2 4
Output
0
题意:n个战士排成一排,分别有个武力值a[i]。你有两种法术,一个是火球(花费x个法力,消灭连续k个战士),一个是激怒(花费y个法力,选择相邻两个战士,武力值大的会消灭武力值小的)。求最后留下的战士排列成b[i]需要的最小法力花费
思路:原文https://blog.csdn.net/li_wen_zhuo/article/details/107311637
我们只需要将a[]中元素和b[]中元素进行一一比较,找出a[]中那些区间要被删除即可。如果a[]只通过删除某些数不能变成b[]或者a[]中某个应该被删除的区间无法通过上述两种法术完全删除,那么输出-1。
利用两种法术删除某个区间中的所有数,且得到最小法力花费的方法:

设该区间为[l,r],首先看看与该区间相邻的两个数a[l-1],a[r+1]
是否有一个大于区间内的最大值(判断能否只通过法术(2)来消除区间内的所有数)。
如果区间的长度len<k(此时只能通过法术(2)来消除区间内的数),
且上述条件不成立,那么不能完全删除这个区间中的所有数,输出-1

然后就是找出最小的法力花费了:
我们必须使用法术(2)来消除至少len%k个数(因为法术(1)每次都只能消除连续的k个数)。剩下的len-k个数我们就要通过判断来确定使用那种方法了(注:后面的len都是len-=k后的)。

如果用法术(2)删除k个数需要的法力大于等于x(y*k>=x),那么剩下的数就可以
只用法术(1)来删除了。
如果y*k<x且条件1成立,那么就可以用用法术(2)来消除剩下的所有数。
如果y*k<x且条件1不成立,即不能用法术(2)来删除所有数,
那么就用法术(2)删除(len-k)个元素,最后只留下k个元素用法术(1)来消除。
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<string>
#include<iomanip>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
typedef long long ll;
ll a[200005], b[200005]; 
ll x, k, y; ll n, m;
bool gg(ll l, ll r, ll& ans)
{
	if (l > r) return true;
	bool st = false;
	ll maxx = *max_element(a + l, a + l + r);
	if (l - 1 >= 0 && a[l - 1] > maxx)
		st = true;
	if (r + 1 < n && a[r + 1] > maxx) st = true;
	int len = r + 1 - l;
	if (len < k && !st) return false;
	int t = len % k;
	ans += t * y; len -= t;
	if (k * y >= x) ans += len / k * x;
	else if (st) ans += len * y;
	else ans += (len - k) * y + x;
	return true;
}
int main()
{
	
	cin >> n >> m;

		cin >> x >> k >> y;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	for (int i = 1; i <= m; i++)
		cin >> b[i];
	ll posa = 0, posb = 0, s = -1;
	ll ans = 0;
	while (posb < m)
	{
		while (posa < n && a[posa] != b[posb]) posa++;
		if (posa == n)
		{
			cout << -1 << endl; return 0;
		}
		if (!gg(s + 1, posa - 1, ans))
		{
			cout << -1 << endl; return 0;
		}
		s = posa; posb++;
	}
	if (!gg(s + 1, n - 1, ans))
	{
		cout << -1 << endl; return 0;
	}
	cout << ans << endl;

}

E - Merging Towers CodeForces - 1380E

F - Strange Addition CodeForces - 1380F

这两个自己还没会 ,自己会在日后补上。

反思:这次前三个题还是挺容易的,但第三个我是超时了一次才去改代码,然后第四个题自己也不是很会,但前仨的AC速度变快了,但第四个没想出来有点可惜,继续加油

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值