当前位置: 首页 > article >正文

Codeforces Round 974 (Div. 3)

比赛地址 :  

Dashboard - Codeforces Round 974 (Div. 3) - Codeforcesicon-default.png?t=O83Ahttps://codeforces.com/contest/2014

A

模拟

#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

#define endl '\n'
typedef long long LL;
#define pb push_back
#define eb emplace_back
#define PII pair<int,int>
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define int long long

const int N = 2e5 + 10 ;
const int Mod = 1e9 + 7 ;
// int xx[] = { 1,0,-1,0 };
// int yy[] = { 0,1,0,-1 };

LL qmi(LL m, LL k){LL res = 1 % Mod, t = m;while (k){if (k&1) res = res * t % Mod;t = t * t % Mod;k >>= 1;}return res;}


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

B

只用分情况(奇偶)讨论即可 ;

#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

#define endl '\n'
typedef long long LL;
#define pb push_back
#define eb emplace_back
#define PII pair<int,int>
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define int long long

const int N = 2e5 + 10 ;
const int Mod = 1e9 + 7 ;
// int xx[] = { 1,0,-1,0 };
// int yy[] = { 0,1,0,-1 };

LL qmi(LL m, LL k){LL res = 1 % Mod, t = m;while (k){if (k&1) res = res * t % Mod;t = t * t % Mod;k >>= 1;}return res;}


inline void solve(){
	int n , k ; cin >> n >> k ;
	// n-k+1,n
	if(n&1){
		if(k==1) cout << "No" << endl ;
		else{
			// 多少个奇数
			int t = 0 ;
			if(k%2==0) t = k/2 ;
			else t=k/2+1;
			if(t&1) cout << "NO" << endl ; 
			else cout << "Yes" << endl ;
		}
	}else{
		if(k==1) cout << "yes" << endl ;
		else{
			int t = 0 ;
			if(k%2==0) t = k/2 ;
			else t=k/2;
			if(t&1) cout << "NO" << endl ; 
			else cout << "Yes" << endl ;
		}
	}
}
 
signed main(){
    IOS
    int _ = 1;
    cin >> _;
    while(_ --) solve();
    return 0;
}

 C

也是模拟,找到最小不满足哪一个,求出应满足的最小值+1减去原来的sum即可 ;

#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

#define endl '\n'
typedef long long LL;
#define pb push_back
#define eb emplace_back
#define PII pair<int,int>
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define int long long

const int N = 2e5 + 10 ;
const int Mod = 1e9 + 7 ;
// int xx[] = { 1,0,-1,0 };
// int yy[] = { 0,1,0,-1 };

LL qmi(LL m, LL k){LL res = 1 % Mod, t = m;while (k){if (k&1) res = res * t % Mod;t = t * t % Mod;k >>= 1;}return res;}


inline void solve(){
	int n ; cin >> n ;
	vector<int> a(n) ;
	int sum = 0 ;
	for(int& x : a) cin >> x , sum += x ;
	if(n<=2){cout << -1 << endl ; return ;}
	sort(all(a)) ;
	int p = a[n/2] ;
	// 平均财富>p*2;
	int ans = 2*p*n-sum ;
	if(ans<0) cout << 0 << endl ;
	else cout << ans+1 << endl ; 
	
}
 
signed main(){
    IOS
    int _ = 1;
    cin >> _;
    while(_ --) solve();
    return 0;
}

D

二分 + 差分

#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

#define endl '\n'
typedef long long LL;
#define pb push_back
#define eb emplace_back
#define PII pair<int,int>
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define int long long

const int N = 2e5 + 10 ;
const int Mod = 1e9 + 7 ;
// int xx[] = { 1,0,-1,0 };
// int yy[] = { 0,1,0,-1 };

LL qmi(LL m, LL k){LL res = 1 % Mod, t = m;while (k){if (k&1) res = res * t % Mod;t = t * t % Mod;k >>= 1;}return res;}

int n , d , k;

bool cmp(PII& x, PII& y){
	if(x.fi==y.fi) return x.se<y.se;
	return x.fi<y.fi ;
}

inline void solve(){
	cin >> n >> d >> k ;
	vector<PII> a(k) ;
	vector<int> h(n+2,0) ,t(n+1,0);
	for(int i=0;i<k;i++) {
		cin >> a[i].fi >> a[i].se ;
		t[a[i].fi]++ ;
		h[a[i].fi]++ ;
		h[a[i].se+1]-- ;
	}
	vector<int> p(n+2,0) ;
	for(int i=1;i<=n;i++) p[i] = p[i-1] + h[i] ;
	sort(all(a),cmp) ;
	vector<int> cnt(n+1,0) ;
	int la = n-d+1 ; 
	for(int i=1;i<=la;i++){
		int ed = i+d-1;
		// st>=i的下标
		int l = -1 , r = k ;
		while(l+1<r){
			int mid = l+r>>1 ;
			if(a[mid].fi>=i) r = mid ;
			else l = mid ;
		}
		int L = r ;
		// st<=ed的下标 
		l = L-1  ; r = k ;
		while(l+1<r){
			int mid = l+r>>1 ;
			if(a[mid].fi<=ed) l = mid ;
			else r = mid ;
		}
		int R = l ;
		if(R>=L) cnt[i] += R-L+1 ;
		//上面区间一定满足
		// fi<i but ed>=i
		//l = -1 ; r = L ;//双开区间 
		// 不一定有序 , 所以不能二分 
		cnt[i] += p[i]-t[i] ;
	}
	int ma = -1 , mi = 2e18 ;
	int r1 = -1 , r2 = -1 ;
	for(int i=1;i<=la;i++){
		// cout << cnt[i] << " " ;
		if(cnt[i]>ma) ma = cnt[i],r1=i;
		if(cnt[i]<mi) mi = cnt[i],r2=i;
	}
	// cout << endl ;
	cout << r1 << " " << r2 << endl ;
}
 
signed main(){
    IOS
    int _ = 1;
    cin >> _;
    while(_ --) solve();
    return 0;
}


http://www.kler.cn/news/315838.html

相关文章:

  • VSCode引用Eigen库无法识别问题解决
  • LEAN 赋型唯一性(Unique Typing)之 Church-Rosser 定理 (Church-Rosser Theorem)及 赋型唯一性的证明
  • 交换机中的信号线需要差分布置吗?
  • 深度学习自编码器 - 随机编码器和解码器篇
  • Kotlin while 和 for 循环(九)
  • CQRS模型解析
  • 计算机信息系统安全保护等级
  • What is new in .NET 8 and C#12
  • oracle 事务的管理
  • 3.《DevOps》系列K8S部署CICD流水线之部署MetalLB负载均衡器和Helm部署Ingress-Nginx
  • [MySQL]数据库修复(Example:1146 Error )
  • 计算机前沿技术-人工智能算法-大语言模型-最新论文阅读-2024-09-17
  • 【有啥问啥】深度剖析:大模型AI时代下的推理路径创新应用方法论
  • 【Lua坑】Lua协程coroutine无法正常完整执行问题
  • 云盘视频保护神器,支持云盘视频加密与在线播放,配合alist使用,超完美!
  • react + antDesignPro 企业微信扫码登录
  • MySQL缓冲池详解
  • react router v6
  • LLaMA-Factory 使用 alpaca 格式的数据集
  • 【Delphi】通过 LiveBindings Designer 链接控件示例
  • Java笔试面试题AI答之设计模式(5)
  • affine: python仿射变换包
  • 【题解】—— LeetCode一周小结38
  • 解决RabbitMQ设置x-max-length队列最大长度后不进入死信队列
  • 周邦彦,北宋文坛的独特乐章
  • 前端工程化4:从0到1构建完整的前端监控平台
  • 自动化生成与更新 Changelog 文件
  • 花生壳、神卓互联等主流内网穿透技术分享
  • FTP服务
  • 编译 Android 11源码