Codeforces Round 902 (Div. 2)

在这里插入图片描述

Dashboard - Codeforces Round 902 (Div. 2, based on COMPFEST 15 - Final Round) - Codeforces

A. Goals of Victory

思路:求和,取负

AC code:

#include<bits/stdc++.h>
#define endl '\n'
#define int long long
#define fast() ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
using namespace std;

typedef long long LL;
typedef pair<char, int> PCI;
typedef pair<int, int> PII;
const int N = 2e5+10, M = 1001;
const int INF = 0x3f3f3f3f, mod = 998244353;
int T, n, m;
int a[N], b[N];

int gcd(int a, int b){
	if(b) while((a %= b) && (b %= a));
	return a + b;
}
signed main(){
	fast();
	T = 1;
	cin >> T;
	while(T --){
		int sum = 0;
		cin >> n;
		for(int i = 1; i < n; i ++)
		cin >> a[i], sum += a[i];
		
		cout << -sum << endl;
	}
	return 0;
}

B. Helmets in Night Light

题意:有n个村民,需要将通知由P传给每个村民,P传给一个人需要p成本,每个村民可以将情报以bi成本传给ai个人,若要传给所有n个人最小成本是多少

思路:以成本为基准进行排序,优先传给情报小于p且最小的村民,由他向之后的村民进行传递,传递后的村民若传递成本小于p则继续传播,直到传播完所有村民或剩下的村民传播成本均大于p,剩下的村民全部由p成本进行传播,即可得到最小成本

AC code:

#include<bits/stdc++.h>
#define endl '\n'
#define int long long
#define fast() ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
using namespace std;

typedef long long LL;
typedef pair<char, int> PCI;
typedef pair<int, int> PII;
const int N = 2e5+10, M = 1001;
const int INF = 0x3f3f3f3f, mod = 998244353;
int T, n, p, m;
int a[N], b[N];

int gcd(int a, int b){
	if(b) while((a %= b) && (b %= a));
	return a + b;
}

signed main(){
	fast();
	T = 1;
	cin >> T;
	while(T --){
			cin >> n >> m;
			PII q[n + 1];
			for(int i = 0; i < n; i ++)
			cin >> q[i].second;
			for(int i = 0; i < n; i ++)
			cin >> q[i].first;
			
			sort(q, q + n);//以传播代价为基准进行排序

			int ans = m, cnt = 1;//初始需要主动传播一个人
			for(int i = 0; i < n; i ++){
				if(q[i].first >= m) break;//当该人的传播代价大于主动传播的代价
				ans += q[i].first * min(n - cnt, q[i].second);//传播人数达标后不再溢出传播
				cnt += q[i].second;
				if(cnt >= n){
				cnt = n;
				break;
			}
		}
		if(n - cnt){
			ans += m * (n - cnt);//剩下未传播的人主动传播
		}
		cout << ans << endl;
	}
	return 0;
}

C. Joyboard

题意:要在n+1个插槽中填入n+1个非负整数,现在必须为第n+1个位置填入一个不大于m的非负整数,且序列满足ai = ai+1 mod i,填入并分配完的序列中需要正好有k个不同的值,有多少满足条件的分配方式

思路:可证k即不同的值最多为3个,因为无论m有多大,在第一次取余的过程中会变成不大于n的数,再对之后的数取余要么还是该数,要么遇到可以整除的数(1)变为0,所以k最多为3

  • k == 1时:填入的数只能为0,即只有一种情况
  • k == 2时 :
    • 若n > m:则从1到m均可,第一次取余要么归0要么还是该数,一共m种情况
    • 若n <= m: 则1到n-1均可,以及能被n整除的数,一共(n - 1) + m / n种情况
  • k == 3时:
    • n >m只会为2,不可能出现3
    • n <= m时,一共有m种情况,用m减去出现2的情况即为出现3的情况,即m - ((n - 1) + m / n)种情况
  • k >= 3时:不可能

AC code:

#include<bits/stdc++.h>
#define endl '\n'
#define int long long
#define fast() ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
using namespace std;
 
typedef long long LL;
typedef pair<char, int> PCI;
typedef pair<int, int> PII;
const int N = 2e5+10, M = 1001;
const int INF = 0x3f3f3f3f, mod = 998244353;
int T, n, m, k;
//int a[N], b[N];
 
int gcd(int a, int b){
	if(b) while((a %= b) && (b %= a));
	return a + b;
}
 
signed main(){
	fast();
	T = 1;
	cin >> T;
	while(T --){
		cin >> n >> m >> k;
		if(k > 3) cout << 0 << endl;
		else if(k == 1)
		cout << 1 << endl;
		else if(k == 2){
			if(n > m) cout << m << endl;
			else{
				cout << n + m / n - 1 << endl;
			}
		}
		else if(k == 3){
			if(n >= m) cout << 0 <<endl;
			else{
				cout << m - n - m / n + 1 << endl;
			}
		}
	}
	return 0;
}

D. Effects of Anti Pimples

题意:初始a数组的所有元素均为白色,可以任意选择元素染成黑色,之后其选择的所以黑色元素下标的倍数染成绿色,其得分即为所有黑色和绿色的元素的最大值,一共有pow(2, n) -1种选择方式,求所有可能的答案之和

思路:每个位置的贡献次数为该位置下标-1的2的幂,而影响当前位置贡献单次多少的即为其下标倍数的元素,若之后的元素出现大于该位置的元素,该位置贡献即为较大元素。求幂需要用快速幂。

AC code:

#include<bits/stdc++.h>
#define endl '\n'
#define int long long
#define fast() ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
using namespace std;

typedef long long LL;
typedef pair<char, int> PCI;
typedef pair<int, int> PII;
const int N = 2e5+10, M = 1001;
const int INF = 0x3f3f3f3f, mod = 998244353;
int T, n, m;
int a[N], b[N];

int gcd(int a, int b){
	if(b) while((a %= b) && (b %= a));
	return a + b;
}

int qmi(int a, int k)
{
  int res = 1;//res为答案
  while(k)//预处理,本质上为求k的二进制表示,把k次方拆成二进制的形式即若干个2的次幂的和
  {
    if(k & 1)//若当前K的末位为1
    res = (LL)res * a % mod;//a是不断反复平方的
    k >>= 1;
    a = (LL)a * a % mod;
  }
  return res;
}

signed main(){
	fast();
	T = 1;
	//cin >> T;
	while(T --){
		cin >> n;
		for(int i = 1; i <= n; i ++)
		cin >> a[i], b[i] = 0;
		for(int i = 1; i <= n; i ++){
			for(int j = i; j <= n; j += i){
				if(a[j] > b[i])
				b[i] = a[j];//找出每个数的max
			}
		}
		sort(b + 1, b + n + 1);
		int ans = 0;
		for(int i = 1; i <= n; i ++){
			ans = (ans + (b[i] * qmi(2, i - 1)) % mod) % mod;//每个数的最大值pow(2, i)即为该数的贡献
		} 
		cout << ans % mod << endl;
	}
	return 0;
}

/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| ^_^ |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         佛祖保佑AC,永无bug缠身       
*/
  • 4
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值