Codeforces Round 957 (Div. 3)

A. Only Pluses

Problem - A - Codeforces

题意:

Kmes 写了三个整数 a 、 b 和 c ,以便记住他必须给 Noobish_Monk a×b×c 香蕉。

Noobish_Monk 找到了这些整数,并决定做以下最多 5 次的事情:

  • 从这些整数中选择一个
  • 将它增加 11 。

例如,如果是 a=2 、 b=3 和 c=4 ,那么可以将 a 增加三次,再将 b 增加两次。之后是 a=5 、 b=5 、 c=4 。那么香蕉的总数就是 5×5×4=100 。

a×b×c的最大值是多少?Noobish_Monk通过这些运算可以得到的最大值是多少?

思路:

每次对最小的进行操作

AC代码:

#define _CRT_SECURE_NO_WARNINGS 1
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#include<math.h>
using namespace std;
typedef long long ll;
priority_queue<int, vector<int>, greater<int>> pq;
map<int, int>mp;
vector<int>q;
void solve()
{
	int x;
	q.clear();
	for (int i = 0; i < 3; i++)
	{
		cin >> x;
		q.push_back(x);
	}
	int num = 0;
	for (int i = 0; i < 5; i++)
	{
		sort(q.begin(), q.end());
		q[0]++;
	}
	cout << q[0] * q[1] * q[2] << endl;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int t;
	cin >> t;
	while(t--)
	{
		solve();
	}

	return 0;
}

B. Angry Monk

Problem - B - Codeforces

题目大意:

为了庆祝他的康复,k1o0n 烤了一个长达 n 米的巨大马铃薯砂锅。

结果,Noobish_Monk就是受不了土豆,所以他决定毁了 k1o0n 的大餐。他把土豆切成了 k 块,长度是 a1,a2,…,ak 米。

k1o0n 并不喜欢这样。幸运的是,一切都可以补救。为此,k1o0n 可以进行以下操作之一:

  • 选取长度为 ai≥2 的棋子,将其分成长度为 1 和 ai−1 的两个棋子。这样,棋子的数量将增加 1 ;
  • 选取长度为 ai 的一个片段和长度为 aj=1 的另一个片段( i≠j ),将它们合并为长度为 ai+1 的一个片段。这样,棋子的数量将减少 1 。

请帮助 k1o0n 找出将砂锅合并成长度为 n 的一块所需的最少操作数。

例如,如果 n=5、 k=2 和 a=[3,2],最佳操作如下:

  1. 将长度为 2 的棋子分成长度为 2−1=1 和 1 的两块,结果为 a=[3,1,1] 。
  2. 合并长度为 3 的棋子和长度为 1 的棋子,得到 a=[4,1] .
  3. 将长度为 4 的棋子与长度为 1 的棋子合并,得到 a=[5] 。
#define _CRT_SECURE_NO_WARNINGS 1
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#include<math.h>
using namespace std;
typedef long long ll;
priority_queue<int, vector<int>, greater<int>> pq;
map<int, int>mp;
int a[200010];
void solve()
{
	memset(a, 0, sizeof(a));
	int n, k;
	cin >> n >> k;
	for (int i = 1; i <= k; i++)
	{
		cin >> a[i];
	}
	int ans = 0;
	int tt = 0;
	int p;
	for (int i = 1; i <= k; i++)
	{
		if (a[i] > tt)
		{
			p = i;
			tt = a[i];
		}
	}
	for (int i = 1; i <= k; i++)
	{
		if (i != p)
		{
			if (a[i] == 1)
			{
				ans++;
			}
			else if(a[i]>1)
			{
				ans += a[i] - 1;
				ans += a[i];
			}
		}
	}
	cout << ans << endl;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int t;
	cin >> t;
	while(t--)
	{
		solve();
	}

	return 0;
}

思路:

以最大的为基准,把所有都累加到最大上面(为1时直接+1就行,>1时加上该值的两倍-1(分出1和把1合并是两步))

C. Gorilla and Permutation

Problem - C - Codeforces

思路:

其实巨简单(想得太多了反而做不出来),就是求一个最大的f和一个最小的g就行了,根据两个特殊值m和k就行,先输出所有>m且<=k的值(1~n,不能重复),输出<m的值要注意一下,因为我们要让g最小,即<m的要先输出小的再输出大的(因为最后都会得到相同的和,此时就必须要取小的)

AC代码:

#include<bits/stdc++.h>
#define ll long long
#define TEST int T;cin>>T;while(T--)
using namespace std;
void solve() {
    ll n,m,k;
    cin>>n>>m>>k;
    for(int i=n;i>=k;i--) cout<<i<<" ";
    for(int i=k-1;i>=m+1;i--) cout<<i<<" ";
    for(int i=1;i<=m;i++) cout<<i<<" ";
    cout<<"\n";
}
int main() {
    TEST 
    solve();
    return 0;
}


D. Test of Love

Problem - D - Codeforces

AC代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, m, t, h, k,a,b,c,ans, num, sum1,sum,sum2, cnt;
string s, ss;
void solve()
{
    cin >> n >> m >> k;
    cin >> s;
    s = " " + s;
    if (m > n) {
        cout << "YES" << endl;
        return;
    }
    else {
        ans = m;
        for (int i = 1; i <= n; i++) {
            if (ans <= 0) {
                cout << "NO" << endl;
                return;
            }
            if (s[i] == 'L')
                ans = m;
            if (s[i] == 'W') {
                if (k > 0) {
                    if (ans > 1)
                        ans--;
                    else {
                        ans = 1;
                        k--;
                    }
                }
                else
                    ans--;
            }
            if (s[i] == 'C')
                ans--;
        }
    }
    if (ans > 0)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}
int main()
{
    cin >> t;
    while (t--)
        solve();
    return 0;
}

相关推荐

  1. Codeforces Round 957 (Div. 3)

    2024-07-14 10:52:03       21 阅读
  2. Codeforces Round 950 (Div. 3)

    2024-07-14 10:52:03       23 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-14 10:52:03       67 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-14 10:52:03       71 阅读
  3. 在Django里面运行非项目文件

    2024-07-14 10:52:03       58 阅读
  4. Python语言-面向对象

    2024-07-14 10:52:03       69 阅读

热门阅读

  1. 电子版pdf格式标书怎么加盖公章?

    2024-07-14 10:52:03       28 阅读
  2. not enough information C#

    2024-07-14 10:52:03       21 阅读
  3. python 网络爬虫

    2024-07-14 10:52:03       24 阅读
  4. Writing Bazel rules: simple binary rule

    2024-07-14 10:52:03       18 阅读
  5. UVA12342 Tax Calculator 题解

    2024-07-14 10:52:03       23 阅读