Codeforces Round 951 (Div. 2) A - C题解

这是一篇提前写的博客,因为时间不够,花了四十分钟做了A-C,因为题目A - C比较简单,所以简单说一说吧。

A. Guess the Maximum

题意:给你n个数字,选择i和j满足(1<= i < j <= n),如果其中的最大值大于k,那么Bob赢,其他情况Alice赢,问Alice全部获胜的最大k是多少。
题解:很明显可以想到,数字区间越大,那么最大值是不会变小的,一定会越来越大,所以想要找到最大的k,直接枚举相邻两个数字,求出所有数字的最大值的最小值即可,当然最后要减一。
代码:
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const int maxn = 2e6 + 7 ;
const int mod = 998244353 ;
inline ll read() {
	ll x = 0, f = 1 ;
	char c = getchar() ;
	while (c > '9' || c < '0') {
		if (c == '-')
			f = -1 ;
		c = getchar() ;
	}
	while (c >= '0' && c <= '9') {
		x = x * 10 + c - '0' ;
		c = getchar() ;
	}
	return x * f ;
}

ll a[maxn] , b[maxn] , n , m , t ;
ll sum[maxn] , Sum[maxn] , ssum[maxn] , SSum[maxn] , A[maxn] , B[maxn] ;
char s[maxn] ;
void solve(){
	n = read() ;
	for(int i = 1 ; i <= n ; i ++){
		a[i] = read() ;
	}
	ll Min = LONG_LONG_MAX ;
	for(int i = 1 ; i <= n - 1 ; i ++){
		Min = min(Min , max(a[i] , a[i + 1])) ;
	}
	cout << Min - 1 << endl ;
}
int main(){
	t = read() ;
	while(t --){
		solve() ;
	}
	return 0 ;
}

B. XOR Sequences

题意:给你a和b的两个排列,给你n和m,让a序列所有数字异或n,让b序列所有数字异或m,问满足a_i == a_j的连续序列最长是多少。
题解:这道题很明显的结论,就是2的n异或m的最小一位数字1次方,简单来说,比如说第一组样例8异或4等于12,他的二进制是10100,所以答案就是4。得解。
代码:
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const int maxn = 2e6 + 7 ;
const int mod = 998244353 ;
inline ll read() {
	ll x = 0, f = 1 ;
	char c = getchar() ;
	while (c > '9' || c < '0') {
		if (c == '-')
			f = -1 ;
		c = getchar() ;
	}
	while (c >= '0' && c <= '9') {
		x = x * 10 + c - '0' ;
		c = getchar() ;
	}
	return x * f ;
}

ll a[maxn] , b[maxn] , n , m , t ;
ll sum[maxn] , Sum[maxn] , ssum[maxn] , SSum[maxn] , A[maxn] , B[maxn] ;
char s[maxn] ;
void solve(){
	n = read() ;
	m = read() ;
	ll xx = n xor m ;
	ll rt = -1 ;	
	for(ll i = 0 ; i <= 32 ; i ++){
		ll len = (xx >> i) & 1 ;
		if(len == 1){
			rt = i ;
			break ;
		}
	}
	if(rt == -1){
		cout << 1 << endl ;
		return ;
	}
	cout << (ll)pow(2ll , rt) << endl ;
}
int main(){
	t = read() ;
	while(t --){
		solve() ;
	}
	return 0 ;
}

C. Earning on Bets

题意:给你n个数字,每个数字都有初始数字,每个数字对应一个k值,如果他每次获胜,那么会获得a[i] * k的收益,题目给你每个k的值,他想问,构造序列a,满足a的每个数字都能满足a[i] * k > \sum a
题解:求出所有数字的最小公倍数,然后算出是否满足条件即可,如果不满足,那必然永远不会满足,输出-1,如果满足输出答案即可。
代码:
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const int maxn = 2e6 + 7 ;
const int mod = 998244353 ;
inline ll read() {
	ll x = 0, f = 1 ;
	char c = getchar() ;
	while (c > '9' || c < '0') {
		if (c == '-')
			f = -1 ;
		c = getchar() ;
	}
	while (c >= '0' && c <= '9') {
		x = x * 10 + c - '0' ;
		c = getchar() ;
	}
	return x * f ;
}

ll a[maxn] , b[maxn] , n , m , t ;
ll sum[maxn] , Sum[maxn] , ssum[maxn] , SSum[maxn] , A[maxn] , B[maxn] ;
char s[maxn] ;
void solve(){
	n = read() ;
	for(int i = 1 ; i <= n ; i ++){
		a[i] = read() ;
	}
	ll lcm = 1 ;
	for(int i = 1 ; i <= n ; i ++){
		lcm = (lcm * a[i]) / __gcd(lcm , a[i]) ;
	}
	for(int i = 1 ; i <= n ; i ++){
		b[i] = lcm / a[i] ;
	}
	ll ans = 0 ;
	for(int i = 1 ; i <= n ; i ++){
		ans += b[i] ;
	}
	if(ans >= lcm){
		cout << -1 << endl ;
		return ;
	}
	else{
		for(int i = 1 ; i <= n ; i ++){
			cout << b[i] << " " ; 
		}
		cout << endl ;
	}
}
int main(){
	t = read() ;
	while(t --){
		solve() ;
	}
	return 0 ;
}

喜欢作者的记得点赞收藏加关注哦~

作者会持续更新算法和技巧!

  • 12
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
抱歉,根据提供的引用内容,我无法理解你具体想要问什么问题。请提供更清晰明确的问题,我将竭诚为你解答。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Codeforces Round 860 (Div. 2)题解](https://blog.csdn.net/qq_60653991/article/details/129802687)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [【CodeforcesCodeforces Round 865 (Div. 2) (补赛)](https://blog.csdn.net/t_mod/article/details/130104033)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [Codeforces Round 872 (Div. 2)(前三道](https://blog.csdn.net/qq_68286180/article/details/130570952)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小小许愿瓶

我的成长我做主

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值