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;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值