Codeforces Round 925 (Div. 3)

比赛地址

Dashboard - Codeforces Round 925 (Div. 3) - Codeforces

A. Recovering a Small String

直接模拟

复制代码
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
#define lowbit(x) (x&(-x))
#define sz(a) (int)a.size()
#define pb push_back
#define all(a) a.begin(), a.end()
#define int long long
typedef long long LL;
const int mod = 1e9+7;
const int N = 2e5+10;

using namespace std;

inline void solve(){
	int n ; cin >> n ;
	// a a z ; 28
	// a z z : 1 + 26 + 26 = 53
	if(n<=28){
		char c = (char)(n-3+'a') ;
		cout << "aa" <<c << endl; 
	}else if(n<=53){
		char c = (char)(n-28+'a');
		cout << "a" << c << "z" << endl;
	}else{
		char c = (char)(n-53+'a');
		cout << c << "zz" << endl;
	}
	return ;
}
 
signed main()
{
    IOS
    int _ = 1;
    cin >> _;
    while(_ --) solve();
    return 0;
}

B . Make Equal

模拟 , 从后往前遍历,t表示平均值 , 用 x 记录当前每个小于平均值的差 , 如果遇到一个值出现ai>t && ai-t>x,那么表示ai是不可能变成t的,后面需要的少于它多出来的;

复制代码
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
#define lowbit(x) (x&(-x))
#define sz(a) (int)a.size()
#define pb push_back
#define all(a) a.begin(), a.end()
#define int long long
typedef long long LL;
const int mod = 1e9 + 7;
const int N = 2e5 + 10;

using namespace std;

inline void solve() {
	int n ; cin >> n ;
	LL s = 0 ;
	vector<int> a(n+1) ;
	for(int i=1;i<=n;i++) {
		cin >> a[i] ;
		s += a[i] ;
	}
	LL t = s / n ;
	LL x = 0 ;
	bool tag = true ;
	for(int i=n;i>=1;i--){
		if(a[i] < t){
			x += t - a[i] ;
		}else{
			if(a[i]-t > x){
				tag = false;
				break;
			}
			x -= a[i] - t;
		}
	}
	if(tag) cout << "Yes" << endl;
	else cout << "No" << endl;
	
}

signed main()
{
    IOS
	int _ = 1;
    cin >> _;
    while (_--) solve();
    return 0;
}

C. Make Equal Again

模拟

复制代码
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
#define lowbit(x) (x&(-x))
#define sz(a) (int)a.size()
#define pb push_back
#define all(a) a.begin(), a.end()
#define int long long
typedef long long LL;
const int mod = 1e9+7;
const int N = 2e5+10;

using namespace std;

inline void solve(){
	int n ; cin >> n ;
	vector<int> a(n+1);
	for(int i=1;i<=n;i++){
		cin >> a[i] ;
	}
	int i=1,j=n;
	int ans = 0 ;
	if(a[i]!=a[j]){
		while(i<=n&&a[i]==a[1]) i++;
		while(j>=1 && a[j]==a[n]) j--;
		ans = n - max(i-1,n-j);
	}
	else{
		while(i<=n && a[i]==a[1]) i++;
		while(j>=1 && a[j]==a[1]) j--;
		if(j<i) ans = 0 ;
		else ans = j - i + 1 ;
	}
	cout << ans << endl;
}
 
signed main()
{
    IOS
    int _ = 1;
    cin >> _;
    while(_ --) solve();
    return 0;
}

D. Divisible Pairs

哈希表解决!

对于( a + b ) % x = 0 , 那么a % x + b % x = 0 ;

对于(a - b)% y = 0 , 那么a % y == b % y ;

如果知道上面的,那么这道题就很简单了 ;

用哈希表来存对应的pair<int,int>,表示 : {ai%x,ai%y} ;

复制代码
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
#define lowbit(x) (x&(-x))
#define sz(a) (int)a.size()
#define pb push_back
#define all(a) a.begin(), a.end()
#define int long long
#define PII pair<int,int> 
typedef long long LL;
const int mod = 1e9+7;
const int N = 2e5+10;

using namespace std;

int a[N] ;

inline void solve(){
	int n , x , y ;
	cin >> n >> x >> y ;
	for(int i=1;i<=n;i++) cin >> a[i] ;
	int ans = 0 ;
	map<PII,int> mp;
	for(int i=1;i<=n;i++){
		// 求 x - a[i] % x 和 a[i ]% y 组成的pair前面有多少个 
		auto it = mp.find({(x-a[i]%x)%x,a[i]%y});
		if(it!=mp.end()){
			ans += it->second;
		}
		mp[{a[i]%x,a[i]%y}]++;
	} 
	cout << ans << endl;
}
 
signed main()
{
    IOS
    int _ = 1;
    cin >> _;
    while(_ --) solve();
    return 0;
}

E. Anna and the Valentine's Day Gift

贪心模拟题 ;

首先要清楚 : Anan选 后导0 最多的数消除后导0 , 然后Shasha是保护后导0最多的数 ;

遍历每一个元素,将后导0个数不为0的个数存起来,然后排序,然后每次最优都是减小最多的,减去那一部分,最后和m判断即可 ;

复制代码
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
#define lowbit(x) (x&(-x))
#define sz(a) (int)a.size()
#define pb push_back
#define all(a) a.begin(), a.end()
#define int long long
typedef long long LL;
const int mod = 1e9+7;
const int N = 2e5+10;

using namespace std;

int a[N] ;

bool cmp(int x ,int y){
	return x > y ;
}

inline void solve(){
	// Anan选后导0最多的数消除后导0,然后Shasha是保护后导0最多的数
	int n , m ; cin >> n >> m ;
	LL cnt = 0 ;
	vector<int> b ;
	for(int i=1;i<=n;i++){
		int x ; cin >> x ;
		int zero = 0 ;
		while(x%10==0){
			zero++;
			x /= 10 ;
		}
		while(x){
			cnt ++;
			x /= 10 ;
		}
		if(zero) b.push_back(zero);
	}
	sort(b.begin(),b.end(),cmp);
	for(int i=1;i<b.size();i+=2){
		cnt += b[i];
	}
	if(cnt > m) cout << "Sasha" << endl;
	else cout << "Anna" << endl ;
	return ;
}
 
signed main()
{
    IOS
    int _ = 1;
    cin >> _;
    while(_ --) solve();
    return 0;
}
相关推荐
zyl7655 小时前
FlashAttention 详解:从 GPU 硬件、普通 Attention 到分块计算与 Online Softmax
算法
爱读书的小胖9 小时前
LeetCode 122:买卖股票的最佳时机 II(C)解题分析
算法
结局无敌9 小时前
React Native for OpenHarmony 实战:三方库 react-native-modal-dialog 的鸿蒙化适配指南
深度学习·算法·react native·react.js·harmonyos
OPEN-F9 小时前
ROS2系列教程:上位机建图与导航(原理综合)
算法·机器人
weixin_307779139 小时前
C++代码实现MATLAB中的fitrtree函数功能
开发语言·c++·算法·matlab
tomwang03229 小时前
路径优化建模、优化算法分类及工程化小结
算法·数学建模·分类
小羊没烦恼!9 小时前
Ajax与JSON的一些总结
android·java·前端·数据库·mysql·算法·okhttp
2501_9269783310 小时前
人机通信协议--人和机器之间的交互想象
人工智能·经验分享·算法·ai写作
行者全栈架构师10 小时前
【鸿蒙心迹】互动卡片全链路——把核心功能放到桌面(FormKit 实战)(HarmonyOS 7.x)
前端·算法·架构
无定义_10 小时前
10.11日常训练
算法