Pinely round 3 (div1 + div2) A - C题解

首先先声明,这是作者的想法,严格证明都是比赛后证明的,如果有地方不妥,希望大家踊跃提出,作者会立刻改正虚心接受。

如果喜欢作者记得点赞关注哦~~~

A. Distinct Buttons

题意:一个遥控器一共四个方向,最多使用三个,使用四个会使遥控器坏掉,问从(0 , 0)出发,是否可以到达这n个点。
题解:统计方向即可。

代码:

#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const int maxn = 2e5 + 7 ;
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 ;
}
char s[maxn] , S[maxn] ;
ll t , n , k , q , a[maxn] ;
bool vis[maxn] ;
ll b[maxn] ;
void solve(){
	n = read() ;
	for(int i = 1 ; i <= 4 ; i ++){
		vis[i] = 0 ;
	}
	for(int i = 1 ; i <= n ; i ++){
		a[i] = read() ;
		b[i] = read() ;
	}
	for(int i = 1 ; i <= n ; i ++){
		if(a[i] < 0){
			vis[1] = 1 ;
		}
		if(a[i] > 0){
			vis[2] = 1 ;
		}
		if(b[i] < 0){
			vis[3] = 1 ;
		}
		if(b[i] > 0){
			vis[4] = 1;
		}
	}
	int Cnt = 0 ;
	for(int k = 1 ; k <= 4 ; k ++){
		if(vis[k] == 1){
			Cnt ++ ;
		}
	}
	if(Cnt <= 3){
		cout << "YES\n" ;
		return ;
	}
	cout << "NO\n" ;
}
int main(){
	t = read() ;
	while(t --){
		solve() ;
	}
	return 0 ;
}


B. Make Almost Equal With Mod

题意:一共有n个数,要选出一个x作为模数,让所有的数字(mod)X后只有两个数字。

题解:首先如果有奇数有偶数,可以直接mod 2 , 这很显然。再看数据很大,10的18次方,可以想到二进制枚举。

代码:

#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const int maxn = 1e6 + 7 ;
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 ;
}
char s[maxn] , S[maxn] ;
ll t , n , k , q ;
bool vis[maxn] ;
ll b[maxn] ;
void solve(){
	n = read() ;
	vector < ll > a(n) ;
	for(int i = 0 ; i < n ; i ++){
		a[i] = read() ;
	}
	ll ji = 0 , ou = 0 ;
	for(int i = 0 ; i < n ; i ++){
		if(a[i] % 2ll == 0){
			ou ++ ;
		}
		else{
			ji ++ ;
		}
	}
	if(ou > 0 && ji > 0 ){
		cout << 2 << endl ;
		return ;
	}
	for(int i = 1 ; ; i ++){
		ll res = (1ll << i) ;
		set < ll > q ;
		for(auto it : a){
			q.insert(it % res) ;
		}
		if(q.size() == 2){
			cout << res << endl ;
			return ;
		}
	}
}
int main(){
	t = read() ;
	while(t --){
		solve() ;
	}
	return 0 ;
}

C. Heavy Intervals

题意:一共给你三个数组a , b , c ,你可以任意将这三组数据排序,求出可以将(b[i] - a[i]) * c[i] (i = 1 - n)求和的最大值。
题解:首先只要没有两条相交的线段(不是包含,而是相交) ,可以看到(b[i] - a[i])全部的和是一定的,那必然要将小的值给大的区间。因为我们想让每个区间长度最大,所以如果L确定,有R1 > L , R2 > L , R2 > R1 ,我们应该优先选择R1 , 这样可以使每个区间的长度最大。所以从大数开始枚举,二分求出第一个比他大的数字,依次进行,可以想到用set维护,好处理一点。
备注:没有看到resubmission会扣分,手欠又交了一发,导致掉了打分!
代码:
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const int maxn = 4e5 + 7 ;
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 ;
}
char s[maxn] , S[maxn] ;
ll t , n , k , q , a[maxn] , c[maxn] ;
bool vis[maxn] ;
ll b[maxn] , d[maxn] ;
void solve(){
	n = read() ;
	for(int i = 1 ; i <= n ; i ++){
		a[i] = read() ;
	}
	for(int i = 1 ; i <= n ; i ++){
		b[i] = read() ;
	}
	for(int i = 1 ; i <= n ; i ++){
		c[i] = read() ;
	}
	ll ans = 0 ;
	sort(a + 1 , a + n + 1 , greater<>()) ;
	sort(b + 1 , b + n + 1 , greater<>()) ;
	multiset < ll > q ;
	for(int i = 1 ; i <= n ; i ++){
		q.insert(b[i]) ;
	}
	for(int i = 1 ; i <= n ; i ++){
		auto it = q.lower_bound(a[i]) ;
//		cout << *it << endl ;
		d[i] = *it - a[i] ;
		q.erase(*it) ;
	}
	sort(c + 1 , c + n + 1) ;
	sort(d + 1 , d + n + 1 , greater<>()) ;
	for(int i = 1 ; i <= n ; i ++){
		ans += d[i] * c[i] ;
	}
	cout << ans << endl ;
}
int main(){
	t = read() ;
	while(t --){
		solve() ;
	}
	return 0 ;
}

  • 10
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Codeforces Round 894 (Div. 3) 是一个Codeforces举办的比赛,是第894轮的Div. 3级别比赛。它包含了一系列题目,其中包括题目E. Kolya and Movie Theatre。 根据题目描述,E. Kolya and Movie Theatre问题要求我们给定两个字符串,通过三种操作来让字符串a等于字符串b。这三种操作分别为:交换a中相同位置的字符、交换a中对称位置的字符、交换b中对称位置的字符。我们需要先进行一次预处理,替换a中的字符,然后进行上述三种操作,最终得到a等于b的结果。我们需要计算预处理操作的次数。 根据引用的讨论,当且仅当b[i]==b[n-i-1]时,如果a[i]!=a[n-i-1],需要进行一次操作;否则不需要操作。所以我们可以遍历字符串b的前半部分,判断对应位置的字符是否与后半部分对称,并统计需要进行操作的次数。 以上就是Codeforces Round 894 (Div. 3)的简要说明和题目E. Kolya and Movie Theatre的要求。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [Codeforces Round #498 (Div. 3) (A+B+C+D+E+F)](https://blog.csdn.net/qq_46030630/article/details/108804114)[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^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *3* [Codeforces Round 894 (Div. 3)A~E题解](https://blog.csdn.net/gyeolhada/article/details/132491891)[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^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

小小许愿瓶

我的成长我做主

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

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

打赏作者

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

抵扣说明:

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

余额充值