Codeforces Round 900 (Div. 3)(A-F)

比赛链接  :

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

A. How Much Does Daytona Cost?

题面 : 

思路 :

在序列中只要找到k,就返回true ;

代码 : 

#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'

using namespace std;
typedef long long LL;
const int N = 2e5+10;

inline void solve(){
	int n , k ; cin >> n >> k ;
	bool tag = false;
	for(int i=0;i<n;i++){
		int x ; cin >> x ;
		if(x==k) tag = true;
	}
	if(tag) cout << "Yes" << endl;
	else cout << "No" << endl;
	return ;
}
 
int main()
{
    IOS
    int _ = 1;
    cin >> _;
    while(_ --) solve();
    return 0;
}

B. Aleksa and Stack

题面 : 

思路 :

在这道题中,只要满足任意两个相邻数的和,不能够不是3的倍数,且数组单调递增,那么便可以构造出这样一个序列,每两个相邻数中第一个数 mod 3 = 0,另一个数mod 3 = 1 ,然后递增的话,就可以使a1 = 3 *1 , a2= a1 + 1,a3 = 3 * 2,a4 = a3 + 1,即可满足题目条件;

代码

#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'

using namespace std;
typedef long long LL;
int gcd(int a,int b){ return b==0 ? a : gcd(b,a%b); }
int lcm(int a,int b){ if(a==0||b==0) return 0; return (a*b)/gcd(a,b); }
bool is_prime(int x){if(x<2) return false;
for(int i=2;i<=x/i;i++) if(x%i==0) return false; return true;}
//numbers.erase(std::unique(numbers.begin(), numbers.end()), numbers.end()); // 去重操作
const int N = 2e5+10;

// 任意两个数的和不是3的倍数 

// 0, 1, 2
// 3 , 4 , 6, 7 

inline void solve(){
	int n ; cin >> n ;
	int x = 3;
	while(n>1){
		cout << x << " " << x + 1 << " ";
		x += 3;
		n -= 2;
	}
	if(n) cout << x ;
	cout << endl ;
	return ;
	
}
 
int main()
{
    IOS
    int _ = 1;
    cin >> _;
    while(_ --) solve();
    return 0;
}

 C. Vasilije in Cacak

题面 : 

思路 : 

对于从  [1 ,n ]  中 选k个数 的 和为x;

假如 n = 2 (并且假设k = 2,下面一样):

         1,2 --> 1, 2, 3
n = 3 :

        1, 2 ,3 : 1,2,3,4,5,6 选两个 : 3-5 
n = 4 :

        1,2,3,4 : 3-7 :  

那么我们就可以发现一个规律 : 在[1,n]中取k个数和的范围是[最小的k个数相加,最大的k个数相加];

为了计算的方便,我们可以使用等差数列求和 : s = n*a1+(n-1)*n*d/2  ;

代码 : 

#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'

using namespace std;
typedef long long LL;

LL n , k , x ;

// [1,n] 中 选k个数 的 和为x;

// 1,2 --> 1, 2, 3
//1, 2 ,3 : 1,2,3,4,5,6 选两个 : 3-5 
// 1,2,3,4 : 3-7 :  

// 等差数列求和 : s = n*a1+(n-1)*n*d/2 

inline void solve(){
	cin >> n >> k >> x;
	LL l = (1+k)*k/2 , r = (n+n-k+1)*k/2;
	if(x>=l && x<=r) cout << "Yes" << endl;
	else cout << "No" << endl;
	return ;
}
 
int main()
{
    IOS
    int _ = 1;
    cin >> _;
    while(_ --) solve();
    return 0;
}

D. Reverse Madness

题面

思路 : 

l和r都是单调递增的,且对于每一段区间都是不相交的,所有可以很快找到x对应的li和ri来满足li<=x && x<=ri ;

找到之后就是进行区间的反转,对于每个区间假设li = 2,ri =6,如果x = 4,则a=b=4,如果x=3,则a=3,b=5;那么说明是关于终点对称的,那么就可以使用前缀和算法,来对每个点进行反转次数的统计,如果统计次数为偶那就不用反转了,为奇,则要反转,具体请看代码;

代码

#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'

using namespace std;
typedef long long LL;
const int N = 2e5+10;

inline void solve(){
	int n,k;cin >> n >> k ;
	string s ; cin >> s ;
	s = ' ' + s ;
	vector<int> l(k+1) , r (k+1) ;
	for(int i=1;i<=k;i++) cin >> l[i] ;
	for(int i=1;i<=k;i++) cin >> r[i] ;
	int q ; cin >> q ;
	vector<int> x(q+1) ;
	for(int i=1;i<=q;i++) cin >> x[i] ;
	vector<pair<int,int>> sum(n+3) ;
	for(int i=1;i<=q;i++){
		int pos = lower_bound(r.begin()+1,r.end(),x[i]) - r.begin();
		int a = min(x[i] , r[pos]+l[pos]-x[i]);
		int b = max(x[i],r[pos]+l[pos]-x[i]);
		sum[a].first++ ; sum[b+1].first--;
		sum[a].second = b ; sum[b].second = a ;
	}
	for(int i=1;i<n;i++){
		sum[i].first += sum[i-1].first ;
	}
	int start = -1 , end = -1 ;
	for(int i=1;i<=n;i++){
		if(sum[i].first % 2 == 1){
			start = i ;
			int end = sum[i].second ;
			while(start <= end){
				while(start<=end && sum[start].first % 2 == 1){
					swap(s[start],s[end]);
					start ++;
					end--;
				}
				while(start <= end && sum[start].first % 2 == 0){
					start ++;
					end -- ;
				}
			}
			i = sum[i].second ;
		}
	}
	for(int i=1;i<=n;i++) cout << s[i] ;
	cout << endl; 
}
 
int main()
{
    IOS
    int _ = 1;
    cin >> _;
    while(_ --) solve();
    return 0;
}

E. Iva & Pav

题面 :

思路 : 

// f(l,r)=al & al+1 &…& ar
// 给定一个 l , k ,求最大的r,满足f(l , r) >= k ;
// 定l,则f随着r单调递减 
// & : 按位与 

按位与的特点是,对于某一位,[l,r]上的所有数的该位上为1,结果才为1,那么我们可以采用前缀和的思想,用bit[i][j]来存[1,i]上第j位上为1的个数,具体实现请看代码,再获得bit数组之后,因为在l确定之后,f(l,r)随着r的增大具有单调递减的性质,所有可以使用二分来进行操作;

具体实现请看代码 ;

代码 : 

// f(l,r)=al & al+1 &…& ar
// 给定一个 l , k ,求最大的r,满足f(l , r) >= k ;
// 定l,则f随着r单调递减 
// & : 按位与 
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'

using namespace std;
typedef long long LL;
const int N = 2e5 + 10 ;

inline void solve(){
	int n ; cin >> n ;
	vector<array<int,32>> bit(n+1);
	for(int i=1;i<=n;i++){
		int x ; cin >> x ;
		for(int j = 0;j<32;j++){
			bit[i][j] = 0 ;
			bit[i][j] += x % 2 ;
			x /= 2 ;
			bit[i][j] += bit[i-1][j] ; // 进行前缀和操作,统计i前面j位上为1的个数 
		}	
	} 
	auto check = [&](int l,int r ,int c){
		vector<int> b(32) ;
		for(int i=0;i<32;i++){
			b[i] = bit[r][i] - bit[l-1][i] ;
		}
		int ans = 0 ;
		for(int i=0;i<32;i++){
			if(b[i]==r-l+1) ans += pow(2,i);
		}
		return ans >= c ; 
	};
	int q ; cin >> q ;
	while(q--){
		int l , k ; cin >> l >> k ;
		int L = l, R = n;
		int ans = -1 ;
		while(L<=R){
			int mid = (L+R)>>1 ;
			if(check(l,mid,k)){
				ans = mid ;
				L = mid + 1; 
			}else{
				R = mid - 1 ;
			}
		}
		cout << ans << " " ;
	}
	cout << endl ;
}
 
int main()
{
    IOS
    int _ = 1;
    cin >> _;
    while(_ --) solve();
    return 0;
}

F. Vasilije Loves Number Theory

题面 : 

思路 : 

  •  1 : n *= x,然后问是否存在一个a使得gcd(n,a)=1并且n*a的约数个数等于n,
  • gcd(n,a)=1 --> n,a互质
  • 由于n,a互质,那么 d(n)*d(a)=d(n*a),那么就是要d(a) = n / d(n),所以n % d(n)一定要等于零 

然后就可以通过唯一分解定理来解;

具体实现请看代码 :

代码

#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'

using namespace std;
typedef long long LL;
const int N = 2e5+10;

// 1 : n *= x,然后问是否存在一个a使得gcd(n,a)=1并且n*a的约数个数等于n,
// gcd(n,a)=1 --> n,a互质
// --> d(n)*d(a)=d(n*a),那么就是要d(a) = n / d(n),所以n % d(n)一定要等于零 

inline void solve(){
	int n,q;cin>>n>>q;
	int cnt = 1 ; // 记录因数的数量 
	map<int,int> doc ;
	// 质因数分解 : 
	// num = b1^c1 + b2 ^c2 + .... + bn^cn ; 
	for(int i=2;i*i<=n;i++){
		// i相当于上面的b,c相当于上面的c ; 
		if(n%i==0){
			int c =  0 ;
			while(n%i==0) n/=i,c++;
			doc[i] = c ;
			cnt *= (c+1);
		}
	}
	if(n>1) doc[n] = 1 , cnt *= 2 ; // 最后剩下的n本身也是一个质因数 
	int now = cnt;auto doc2 = doc ;
	while(q--){
		int op ; cin >> op ;
		if(op == 2){
			now = cnt  ;
			doc2 = doc ;
		}else{
			int x ; cin >> x ;
			for(int i=2;i*i<=x;i++){
				if(x%i==0){
					int c =  0 ;
					while(x%i==0) x/=i,c++;
					now /= (doc2[i]+1);
					doc2[i] += c; 
					now *= (doc2[i]+1);
				}
			}
			if(x>1){
				now /= (doc2[x]+1);
				doc2[x]+=1;
				now *= (doc2[x]+1);
			}
			int t = now  ;
			for(auto it:doc2){
				int x = it.first ;
				int y = it.second ;
				while(y>0 && t % x== 0){
					t /= x ;
					y -- ;
				}
			}
			cout << (t==1?"YES":"NO")<<endl; 
		}
	}
}
 
int main()
{
    IOS
    int _ = 1;
    cin >> _;
    while(_ --) solve();
    return 0;
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/284431.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

将PPT4页并排成1页

将PPT4页并排成1页打印 解决方法: 方法一 在打印时选择&#xff1a; 打开 PPT&#xff0c;点击文件选项点击打印点击整页幻灯片点击4张水平放置的幻灯平页面就会显示4张PPT显示在一张纸上 方法二 另存为PDF&#xff1a; 打开电脑上的目标PPT文件&#xff0c;点击文件点击…

数据结构期末复习(fengkao课堂)

学习数据结构时&#xff0c;以下建议可能对您有所帮助&#xff1a; 理解基本概念&#xff1a;首先&#xff0c;确保您理解数据结构的基本概念&#xff0c;例如数组、链表、栈、队列、树、图等。了解它们的定义、特点和基本操作。 学习时间复杂度和空间复杂度&#xff1a;了解如…

深度学习中Batch/Layer/Instance/Group normalization方法

图片中&#xff0c;N是batch size&#xff0c; c是channel。 BN&#xff1a;在每一个channel内&#xff0c;对H&#xff0c;W&#xff0c;Batch做平均LN&#xff1a;在每一个batch内&#xff0c;对H&#xff0c;W&#xff0c;Channel做平均IN&#xff1a;在每一个channel和bat…

数据结构:队列(链表和数组模拟实现)

目录 1.何为队列 2.链表模拟实现 2.1 节点和队列创建 2.2 初始化队列 2.3 入队操作 2.4 出队操作 2.5 遍历队列 2.6 获取队首和队尾元素 2.7 判断队列是否为空 2.8 完整实现 3. 数组模拟实现 3.1 创建队列 3.2 入队和出队操作 3.3 遍历队列 3.4 获取队首和队尾元…

LLM应用的分块策略

每日推荐一篇专注于解决实际问题的外文&#xff0c;精准翻译并深入解读其要点&#xff0c;助力读者培养实际问题解决和代码动手的能力。 欢迎关注公众号 原文标题&#xff1a;Chunking Strategies for LLM Applications 原文地址&#xff1a;https://www.pinecone.io/learn/c…

FPGA项目(13)——基于FPGA的电梯控制系统

1.摘要 随着科技的发展&#xff0c;电梯早在上个世纪就已进入人们的生活。对于电梯的控制&#xff0c;传统的方法是使用继电器——接触器控制系统进行控制。随着EDA技术的发展&#xff0c;FPGA已广泛应用于各项电子设计中&#xff0c;本设计即利用FPGA来实现对电梯控制系统的设…

事务失效的十种常见场景

学习事务失效场景 1 概述 事务的传播类型isolationTransactionnal注解属性 事务方法未被Spring管理方法使用final类型修饰非public修饰的方法同一个类中的方法相互调用方法的事务传播类型不支持事务异常被内部catch&#xff0c;程序生吞异常数据库不支持事务未配置开启事务错…

媒体捕捉-拍照

引言 在项目开发中&#xff0c;从媒体库中选择图片或使用相机拍摄图片是一个极为普遍的需求。通常&#xff0c;我们使用UIImagePickerController来实现单张图片选择或启动相机拍照。整个拍照过程由UIImagePickerController内部实现&#xff0c;无需我们关心细节&#xff0c;只…

Spring Boot整合 EasyExcel 实现复杂 Excel 表格的导入与导出功能

文章目录 1. 简介2. 引入依赖3. 导入功能实现3.1 创建实体类3.2 编写导入 Controller3.3 编写导入页面 4. 导出功能实现4.1 编写导出 Controller4.2 编写导出页面 5. 启动应用 &#x1f388;个人主页&#xff1a;程序员 小侯 &#x1f390;CSDN新晋作者 &#x1f389;欢迎 &…

HttpClient入门

HttpClient入门 简介 HttpClient 是 Apache HttpComponents 项目中的一个开源的 Java HTTP 客户端库&#xff0c;用于发送 HTTP 请求和处理 HTTP 响应。它提供了一组强大而灵活的 API&#xff0c;使得在 Java 程序中执行 HTTP 请求变得相对简单 maven依赖 org.apache.httpco…

C语言操作符下

在这篇文章中&#xff0c;主要讲解关系操作符、条件操作符、逻辑操作符&#xff0c;及其短路。 一. 关系操作符 C语言用于比较的表达式&#xff0c;称为关系表达式&#xff0c;里面运用的运算符就称“关系运算符”&#xff0c;主要有下面6个&#xff1a; < 小于运算符>…

基于Vite创建简单Vue3工程

首先安装node.js环境&#xff0c;没有node.js环境&#xff0c;便没有npm命令。 1、Vue3创建执行命令 D:\TABLE\test>npm create vuelatestVue.js - The Progressive JavaScript Framework√ 请输入项目名称&#xff1a; ... vue_test √ 是否使用 TypeScript 语法&#xff…

【C++】Windows编译FileZilla Client

按照Compiling FileZilla 3 under Windows - FileZilla Wiki (filezilla-project.org)操作即可。 1.下载安装MSYS2 msys2-x86_64-20220118.exe 2.更新MSYS2 进入MSYS2 MinGW 64-bit shell&#xff0c;运行 pacman -Syu重复退出shell&#xff0c;更新MSYS2。直到没有可更新…

【Maven】工程依赖下载失败错误解决

在使用 Maven 构建项目时&#xff0c;可能会发生依赖项下载错误的情况&#xff0c;主要原因有以下几种&#xff1a; 下载依赖时出现网络故障或仓库服务器宕机等原因&#xff0c;导致无法连接至 Maven 仓库&#xff0c;从而无法下载依赖。 依赖项的版本号或配置文件中的版本号错…

详解Vue3中的事件监听方式

本文主要介绍Vue3中的事件监听方式。 目录 一、v-on指令二、使用符号简写三、事件修饰符四、动态事件名五、常见的监听事件六、自定义事件 在Vue3中&#xff0c;事件监听的方式与Vue2有一些不同。 下面是Vue3中事件监听方式的详细介绍&#xff1a; 一、v-on指令 Vue3中仍然使…

[嵌入式AI从0开始到入土]9_yolov5在昇腾上推理

[嵌入式AI从0开始到入土]嵌入式AI系列教程 注&#xff1a;等我摸完鱼再把链接补上 可以关注我的B站号工具人呵呵的个人空间&#xff0c;后期会考虑出视频教程&#xff0c;务必催更&#xff0c;以防我变身鸽王。 第一章 昇腾Altas 200 DK上手 第二章 下载昇腾案例并运行 第三章…

OCP NVME SSD规范解读-3.NVMe管理命令-part2

NVMe-AD-8&#xff1a;在某些情况下&#xff08;如Sanitize命令、Format NVM命令或TCG Revert方法后数据被清除&#xff09;&#xff0c;设备应允许读取已清除的LBAs而不产生错误&#xff0c;并在最后一次清除完成后&#xff0c;对未写入LBAs的读取返回所有零值给主机 NVMe-AD…

【北亚数据恢复】mysql表被truncate,表数据被delete的数据恢复案例

云服务器数据恢复环境&#xff1a; 华为ECS云服务器&#xff0c;linux操作系统&#xff0c;mysql数据库&#xff08;innodb引擎&#xff09;。作为网站服务器使用。 云服务器故障&#xff1a; 在执行mysql数据库版本更新测试时&#xff0c;误将本应该在测试库上执行的sql脚本执…

【JavaScript】浮点数精度问题

✨ 专栏介绍 在现代Web开发中&#xff0c;JavaScript已经成为了不可或缺的一部分。它不仅可以为网页增加交互性和动态性&#xff0c;还可以在后端开发中使用Node.js构建高效的服务器端应用程序。作为一种灵活且易学的脚本语言&#xff0c;JavaScript具有广泛的应用场景&#x…

移动端开发框架mui代码在安卓模拟器上运行2(HbuilderX连接到模拟器)模拟器窗口及多开设置

开发工具 HBuilder X 3.8.12.20230817 注意&#xff1a;开发工具尽量用最新的或较新的。太旧的版本在开发调试过程中可能会出现莫名其妙的问题。 接上篇&#xff0c;移动端开发框架mui代码在安卓模拟器上运行&#xff08;HbuilderX连接到模拟器&#xff09;&#xff0c;这篇主要…