Codeforces 845 简要题解

本文详细解答了Codeforces 845比赛中A至G七道题目,涉及逻辑推理、模拟和图论策略。对于每道题,提供了思路分析和相应的代码实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

文章目录


传送门

A题

传送门
题意: 2 n 2n 2n个人下棋,分为两个阵营,每个阵营 n n n个人,每个人有一个积分,积分高的能赢积分低的,问如果你可以随意选人,然后每场比赛随机安排对局,最后 A A A阵的棋手能否全胜。


思路:
看积分第 n n n大的和积分第 n + 1 n+1 n+1大的这两个人的积分是否相同


代码:

#include<bits/stdc++.h>
#define ri register int
#define fi first
#define se second
using namespace std;
const int rlen=1<<18|1;
inline char gc(){
   
   
	static char buf[rlen],*ib,*ob;
	(ib==ob)&&(ob=(ib=buf)+fread(buf,1,rlen,stdin));
	return ib==ob?-1:*ib++;
}
inline int read(){
   
   
	int ans=0;
	char ch=gc();
	while(!isdigit(ch))ch=gc();
	while(isdigit(ch))ans=((ans<<2)+ans<<1)+(ch^48),ch=gc();
	return ans;
}
const int N=205;
int n,a[N];
int main(){
   
   
	n=read();
	for(ri i=1;i<=n*2;++i)a[i]=read();
	sort(a+1,a+2*n+1);
	puts(a[n]^a[n+1]?"YES":"NO");
	return 0;
}

B题

传送门
题意:给你长度为 6 6 6的数字串,问你最少改几个位置可以让前三个位置的数字和等于后三个位置的数字和。


思路:按照题意模拟。
代码:

#include<bits/stdc++.h>
#define ri register int
#define fi first
#define se second
using namespace std;
const int rlen=1<<18|1;
inline char gc(){
   
   
	static char buf[rlen],*ib,*ob;
	(ib==ob)&&(ob=(ib=buf)+fread(buf,1,rlen,stdin));
	return ib==ob?-1:*ib++;
}
inline int read(){
   
   
	int ans=0;
	char ch=gc();
	while(!isdigit(ch))ch=gc();
	while(isdigit(ch))ans=((ans<<2)+ans<<1)+(ch^48),ch=gc();
	return ans;
}
const int N=205;
int n,a[N];
int main(){
   
   
	char s[10];
	scanf("%s",s);
	int cnt=0;
	for(ri i=0;i<6;++i)cnt+=i<3?s[i]-48:48-s[i];
	priority_queue<int>q;
	int ans=0;
	if(cnt>0){
   
   
		for(ri i=3;i<6;++i)q.push(9-(s[i]-48));
		for(ri i=0;i<3;++i)q.push((s[i]-48)-0);
		while(cnt&&cnt>=q.top())cnt-=q.top(),++ans;
		if(cnt)++ans;
	}
	else if(cnt<0){
   
   
		cnt=-cnt;
		for(ri i=0;i<3;++i)q.push(9-(s[i]-48));
		for(ri i=3;i<6;++i)q.push((s[i]-48)-0);
		while(cnt&&cnt>=q.top())cnt-=q.top(),++ans,q.pop();
		if(cnt)++ans;
	}
	cout<<ans;
	return 0;
}

C题

传送门
题意简述:
你有两台电视,现在有很多节目,相互之间不能交叉播放,问你能否通过合理安排使得放完所有节目且每台电视上的节目都不相交。


思路:按照题意模拟。.


代码:

#include<bits/stdc++.h>
#define ri register int
#define fi first
#define se second
using namespace std;
const int rlen=1<<18|1;
inline char gc(){
   
   
	static char buf[rlen],*ib,*ob;
	(ib==ob)&&(ob=(ib=buf)+fread(buf,1,rlen,stdin));
	return ib==ob?-1:*ib++;
}
inline int read(){
   
   
	int ans=0;
	char ch=gc();
	while(!isdigit(ch))ch=gc();
	while(isdigit(ch))ans=((ans<<2)+ans<<1)+(ch^48),ch=gc();
	return ans;
}
const int N=2e5+5;
int n,rr[2];
struct Node{
   
   
	
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值