Codeforces Round 957 (Div. 3)(A~E)

目录

A. Only Pluses

B. Angry Monk

C. Gorilla and Permutation

D. Test of Love

E. Novice's Mistake


A. Only Pluses

Problem - A - Codeforces

当三个数更接近与同一个数时,三个的乘积就是最大的。

#include<iostream>
#include<algorithm>
#include<queue>
#include<math.h>
#include<cstring>
#include<map>
#define ll long long
#define TEST int T;cin>>T;while(T--)
#define lowbit(x) x&(-x)
using namespace std;
const int N = 2000100;
const int M = 1e8 + 7;
int base1 = 131, base2 = 13311;
void solve() {
	vector<ll>q;
	for(int i=1,x;i<=3;i++)
	{
		cin>>x;
		q.push_back(x);
	}
	for(int i=1;i<=5;i++)
	{
		sort(q.begin(),q.end());
		q[0]++;
	}
	cout<<q[0]*q[1]*q[2]<<"\n";
}
int main() {
	TEST 
	solve();
	return 0;
}

B. Angry Monk

Problem - B - Codeforces

先找到数组的最大数,不需要对它处理,只需将分出的1和它合并即可,想将a[i]分成a[i]个1需要a[i]-1步,将a[i]个1合并需要a[i]步。

#include<iostream>
#include<algorithm>
#include<queue>
#include<math.h>
#include<cstring>
#include<map>
#define ll long long
#define TEST int T;cin>>T;while(T--)
#define lowbit(x) x&(-x)
using namespace std;
const int N = 200100;
const int M = 1e8 + 7;
int base1 = 131, base2 = 13311;
ll a[N];
void solve() {
	ll n,k;
	cin>>n>>k;
	ll ans=0,p=-1;
	for(int i=1;i<=k;i++) 
	{
		cin>>a[i];
		if(a[i]>ans)
		{
			p=i;
			ans=a[i];
		}
	}
	ll sum=0;
	for(int i=1;i<=k;i++)
	{
		if(i!=p)
		{
			if(a[i]==1) sum++;
			else sum+=a[i]-1,sum+=a[i];
		}
	}
	cout<<sum<<"\n";
}
int main() {
	TEST 
	solve();
	return 0;
}

C. Gorilla and Permutation

Problem - C - Codeforces

我们需要最大化全部f(x)的和,最小化全部g(x)的和。那么我们就需要让大于k的数提早出现并且最大,让小于m的数最晚出现。其他数字顺便排。

#include<iostream>
#include<algorithm>
#include<queue>
#include<math.h>
#include<cstring>
#include<map>
#define ll long long
#define TEST int T;cin>>T;while(T--)
#define lowbit(x) x&(-x)
using namespace std;
const int N = 200100;
const int M = 1e8 + 7;
int base1 = 131, base2 = 13311;
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

模拟+贪心

#include<iostream>
#include<algorithm>
#include<queue>
#include<math.h>
#include<cstring>
#include<map>
#define ll long long
#define TEST int T;cin>>T;while(T--)
#define lowbit(x) x&(-x)
using namespace std;
const int N = 200100;
const int M = 1e8 + 7;
int base1 = 131, base2 = 13311;

void solve()
{
	ll ans=0;
	ll n,m,k;
	string s;
	
    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" << "\n";
    else
        cout << "NO" << "\n";
}
int main() {
	TEST
	solve();
	return 0;
}

E. Novice's Mistake

Problem - E - Codeforces

我们观察ab和n的范围,发现a*n-b最大不超过1000000,所以我们可以暴力求解答案,将求解过程分为n为1位数和二位数,三位数是0。

#include<iostream>
#include<algorithm>
#include<queue>
#include<math.h>
#include<cstring>
#include<map>
#define ll long long
#define TEST int T;cin>>T;while(T--)
#define lowbit(x) x&(-x)
using namespace std;
const int N = 200100;
const int M = 1e8 + 7;
int base1 = 131, base2 = 13311;
ll quick(ll base, ll power) {
	ll ans = 1;
	while (power) {
		if (power & 1) {
			ans = (ans * base);
		}
		base = base * base;
		power >>= 1;
	}
	return ans;
}
void solve() {
	ll n;
	cin >> n;
	if (n == 100) {
		cout << 0 << "\n";
		return ;
	}
	vector<ll>ans_A, ans_B;
	if (n < 10) { //一位数
		for (int a = 1; a <= 10000; a++) {
			for (int b = max(1, a - 6); b < a; b++) {

				ll re = n * (quick(10, a - b) - 1) / 9;
				if (a * n - b == re) {
					ans_A.push_back(a);
					ans_B.push_back(b);

				}
			}
		}
	} else { //两位数
		for (int a = 1; a <= 10000; a++) {
			for (int b = max(1, 2 * a - 6); b < 2 * a ; b++) {
				if (b & 1) {
					ll cnt = 1;
					ll re = 0;
					for (int i = 0; i < (2 * a - b) / 2; i++) {
						re += n * quick(10, cnt);
						cnt += 2;
					}
					re += n / 10;
					if (a * n - b == re) {
						
						ans_A.push_back(a);
						ans_B.push_back(b);
					}
				} else {//偶数可以正常处理
					ll cnt = 0;
					ll re = 0;
					for (int i = 0; i < (2 * a - b) / 2; i++) {
						re += n * quick(10, cnt);
						cnt += 2;
					}
					if (a * n - b == re) {
						
						ans_A.push_back(a);
						ans_B.push_back(b);
					}
				}
			}
		}
	}
	cout << ans_A.size() << "\n";
	for (int i = 0; i < ans_A.size(); i++) {
		cout << ans_A[i] << " " << ans_B[i] << "\n";
	}
}
int main() {
	TEST
	solve();
	return 0;
}

相关推荐

  1. Codeforces Round 957 (Div. 3)

    2024-07-13 10:40:06       22 阅读
  2. Codeforces Round 950 (Div. 3)

    2024-07-13 10:40:06       23 阅读

最近更新

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

    2024-07-13 10:40:06       67 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-13 10:40:06       72 阅读
  3. 在Django里面运行非项目文件

    2024-07-13 10:40:06       58 阅读
  4. Python语言-面向对象

    2024-07-13 10:40:06       69 阅读

热门阅读

  1. C++之STL简介

    2024-07-13 10:40:06       24 阅读
  2. Linux——多路IO

    2024-07-13 10:40:06       25 阅读
  3. 【C++】C++中的extern用法

    2024-07-13 10:40:06       22 阅读
  4. 如何理解李彦宏说的“不要卷模型,要卷应用”

    2024-07-13 10:40:06       17 阅读
  5. 2024年,SEC对加密监管的格局将继续演变

    2024-07-13 10:40:06       20 阅读
  6. Python热门面试题一

    2024-07-13 10:40:06       21 阅读
  7. 从零开始学习嵌入式----C语言数组指针

    2024-07-13 10:40:06       26 阅读
  8. 项目开源能够带来什么?从中得到了什么?

    2024-07-13 10:40:06       20 阅读
  9. 使用Spring Boot创建自定义Starter

    2024-07-13 10:40:06       25 阅读
  10. 面试题所有vue

    2024-07-13 10:40:06       22 阅读
  11. 求职学习day2

    2024-07-13 10:40:06       26 阅读
  12. Log4j的原理及应用详解(一)

    2024-07-13 10:40:06       25 阅读
  13. Log4j的原理及应用详解(二)

    2024-07-13 10:40:06       24 阅读