Codeforces Round 949 (Div. 2) (A~C)

news2025/2/27 21:05:06

1981A - Turtle and Piggy Are Playing a Game 

        

       贪心,每次取x = 2,求最大分数

// Problem: B. Turtle and an Infinite Sequence
// Contest: Codeforces - Codeforces Round 949 (Div. 2)
// URL: https://codeforces.com/contest/1981/problem/B
// Memory Limit: 256 MB
// Time Limit: 1000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define pb push_back
#define x first
#define y second 
#define endl '\n'
#define int long long
const LL maxn = 4e05+7;
const LL N = 5e05+10;
const LL mod = 1e09+7;
const int inf = 0x3f3f3f3f;
const LL llinf = 5e18;
typedef pair<int,int>pl;
priority_queue<LL , vector<LL>, greater<LL> >mi;//小根堆
priority_queue<LL> ma;//大根堆
LL gcd(LL a, LL b){
	return b > 0 ? gcd(b , a % b) : a;
}

LL lcm(LL a , LL b){
	return a / gcd(a , b) * b;
}
int n , m;
vector<int>a(N , 0);
void init(int n){
	for(int i = 0 ; i <= n ; i ++){
		a[i] = 0;
	}
}
void solve() 
{
	cin >> n >> m;
	int l = max(0LL , n - m);
	int r = n + m;
	int ans = 0;
	vector<int>tmp1 , tmp2;
    long long cnt = 0; //统计从高位数起,a,b有多少位不一样
    while(l != r)
    {
        cnt++;
        l >>= 1;
        r >>= 1;
    }
    while(cnt--) r = (r<<1)^1;
    cout << r << endl;
}            
signed main() 
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(10);
    int t=1;
	cin>>t;
    while(t--)
    {
    	solve();
    }
    return 0;
}

1981B - Turtle and an Infinite Sequence 

思路:对于数字i而言,m轮之后的结果是[i - m , i + m]所有数的或。因此只需要求区间或就行了。

// Problem: B. Turtle and an Infinite Sequence
// Contest: Codeforces - Codeforces Round 949 (Div. 2)
// URL: https://codeforces.com/contest/1981/problem/B
// Memory Limit: 256 MB
// Time Limit: 1000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define pb push_back
#define x first
#define y second 
#define endl '\n'
#define int long long
const LL maxn = 4e05+7;
const LL N = 5e05+10;
const LL mod = 1e09+7;
const int inf = 0x3f3f3f3f;
const LL llinf = 5e18;
typedef pair<int,int>pl;
priority_queue<LL , vector<LL>, greater<LL> >mi;//小根堆
priority_queue<LL> ma;//大根堆
LL gcd(LL a, LL b){
	return b > 0 ? gcd(b , a % b) : a;
}

LL lcm(LL a , LL b){
	return a / gcd(a , b) * b;
}
int n , m;
vector<int>a(N , 0);
void init(int n){
	for(int i = 0 ; i <= n ; i ++){
		a[i] = 0;
	}
}
void solve() 
{
	cin >> n >> m;
	int l = max(0LL , n - m);
	int r = n + m;
	int ans = 0;
	vector<int>tmp1 , tmp2;
    long long cnt = 0; //统计从高位数起,a,b有多少位不一样
    while(l != r)
    {
        cnt++;
        l >>= 1;
        r >>= 1;
    }
    while(cnt--) r = (r<<1)^1;
    cout << r << endl;
}            
signed main() 
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(10);
    int t=1;
	cin>>t;
    while(t--)
    {
    	solve();
    }
    return 0;
}

1981C - Turtle and an Incomplete Sequence 

    思路:考虑将操作统一,即满足b_{i} = b_{i - 1} /2 或者 b[i] = b[i - 1] * 2 或者b[i] = b[i - 1] * 2+1。因此放二进制上考虑就是将前一个数右移一位或者在末尾填上0或者1。

接下来考虑从x变成y至少需要多少个操作,首先求出x,y的二进制最长公共前缀,然后将x通过右移操作变成其最长公共前缀,然后再通过填1或者填0来变成y。最后之间剩余的数通过反复*2/2操作即可。

        

// Problem: C. Turtle and an Incomplete Sequence
// Contest: Codeforces - Codeforces Round 949 (Div. 2)
// URL: https://codeforces.com/contest/1981/problem/C
// Memory Limit: 256 MB
// Time Limit: 3000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define pb push_back
#define x first
#define y second 
#define endl '\n'
const LL maxn = 4e05+7;
const LL N = 5e05+10;
const LL mod = 1e09+7;
const int inf = 0x3f3f3f3f;
const LL llinf = 5e18;
typedef pair<int,int>pl;
priority_queue<LL , vector<LL>, greater<LL> >mi;//小根堆
priority_queue<LL> ma;//大根堆
LL gcd(LL a, LL b){
	return b > 0 ? gcd(b , a % b) : a;
}

LL lcm(LL a , LL b){
	return a / gcd(a , b) * b;
}
int n , m;
vector<int>a(N , 0);
void init(int n){
	for(int i = 0 ; i <= n ; i ++){
		a[i] = 0;
	}
}
void solve() 
{
	int n;
	cin >> n;
	int bit[n + 5][32];
	for(int i = 1 ; i <= n ; i ++)
		cin >> a[i];
	vector<int>pos;
	int st = 0 , en = 0;
	for(int i = 1 ; i <= n ; i ++){
		if(a[i] != -1){
			if(!st) st = i;
			pos.pb(i);
			for(int j = 0 ; j < 32 ; j ++){
				bit[i][j] = ((a[i] >> j) & 1);
			}
			en = i;
		}
	}
	int f = 0;
	for(int i = st - 1 ; i >= 1 ; i --){
		if(f == 0){
			a[i] = a[i + 1] * 2;
		}
		else{
			a[i] = a[i + 1] / 2;
		}
		f ^= 1;
	}
	f = 0;
	for(int i = en + 1 ; i <= n ; i ++){
		if(i == 1){
			a[i] = 2;
			continue;
		}
		if(f == 0){
			a[i] = a[i - 1] * 2;
		}
		else{
			a[i] = a[i - 1] / 2;
		}
		f ^= 1;
	}	
	int len = pos.size();
	for(int i = 0 ; i < len - 1; i ++){
		int l = a[pos[i]] , r = a[pos[i + 1]];
		int tmp = l;
		int len1 = 0 , len2 = 0;
		while(tmp){
			tmp /= 2;
			len1++;
		}
		tmp = r;
		while(tmp){
			tmp/=2;
			len2++;
		}
		int tot = 0;
		for(int j = 0 ; j < min(len1 , len2) ; j ++){
			if(bit[pos[i]][len1 - j - 1] == bit[pos[i + 1]][len2 - j - 1])
				tot++;
			else
				break;
		}
		int need = len1 + len2 - 2 * tot;
		//cout << l << " " << r << " " << need << endl;
		if(pos[i + 1] - pos[i]  < need || (pos[i + 1] - pos[i] - need) % 2 != 0){
			cout << -1 << endl;
			return;
		}
		int need1 = len1 - tot;
		int need2 = len2 - tot;
		int po = pos[i] + 1;
		for(int j = 0 ; j < need1 ; j ++){
			a[po] = a[po - 1] / 2;
			po++;
		}
		for(int j = 0 ; j < need2 ; j ++){
			if(bit[pos[i + 1]][len2 - tot - j - 1] == 0){
				a[po] = a[po - 1] * 2;
			}
			else{
				a[po] = a[po - 1] * 2 + 1;
			}
			po++;
		}
		int f = 1;
		for(po ; po < pos[i + 1] ; po++){
			if(f == 1){
				a[po] = a[po - 1] * 2;
			}
			else{
				a[po] = a[po - 1] / 2;
			}
			f ^= 1;
		}
	}
	for(int i = 1 ; i <= n ; i ++){
		cout << a[i] << " ";
	}
	cout << endl;
}            

int main() 
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(10);
    int t=1;
	cin>>t;
    while(t--)
    {
    	solve();
    }
    return 0;
}

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

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Java项目对接redis,客户端是选Redisson、Lettuce还是Jedis?

JAVA项目对接redis&#xff0c;客户端是选Redisson、Lettuce还是Jedis&#xff1f; 一、客户端简介1. Jedis介绍2. Lettuce介绍3. Redisson介绍 二、横向对比三、选型说明 在实际的项目开发中&#xff0c;对于一个需要对接Redis的项目来说&#xff0c;就面临着选择合适的Redis客…

G4 - 可控手势生成 CGAN

&#x1f368; 本文为&#x1f517;365天深度学习训练营 中的学习记录博客&#x1f356; 原作者&#xff1a;K同学啊 目录 代码总结与心得 代码 关于CGAN的原理上节已经讲过&#xff0c;这次主要是编写代码加载上节训练后的模型来进行指定条件的生成 图像的生成其实只需要使用…

unity2020打包webGL时卡进程问题

我使用的2020.3.0f1c1&#xff0c;打包发布WEB版的时候会一直卡到asm2wasm.exe这个进程里&#xff0c;而且CPU占用率90%以上。 即使是打包一个新建项目的空场景也是同样的问题&#xff0c;我尝试过一直卡在这里会如何&#xff0c;结果还真打包成功了。只是打包一个空场景需要20…

下载HF AutoTrain 模型的配置文件

下载HF AutoTrain 模型的配置文件 一.在huggingface上创建AutoTrain项目二.通过HF用户名和autotrain项目名,拼接以下url,下载模型列表(json格式)到指定目录三.解析上面的json文件、去重、批量下载模型配置文件(权重以外的文件) 一.在huggingface上创建AutoTrain项目 二.通过HF用…

微信公众号【原子与分子模拟】: 熔化温度 + 超导电性 + 电子化合物 + 分子动力学模拟 + 第一性原理计算 + 数据处理程序

往期内容主要涵盖&#xff1a; 熔化温度 超导电性 电子化合物 分子动力学模拟 第一性原理计算 数据处理程序 【1】熔化温度 分子动力学 LAMMPS 相关内容 【文献分享】分子动力学模拟 LAMMPS 熔化温度 晶体缺陷 熔化方法 LAMMPS 文献&#xff1a;金属熔化行为的局域…

Mac安装第三方软件的命令安装方式

场景&#xff1a; 打开终端命令行&#xff0c;sudo xattr -rd com.apple.quarantine&#xff0c;注意最后quarantine 后面加一个空格&#xff01;然后打开Finder&#xff08;访达&#xff09;&#xff0c;点击左侧的 应用程序&#xff0c;找到相关应用&#xff0c;拖进终端qua…

HackTheBox-Machines--Bashed

Bashed 测试过程 1 信息收集 NMAP 80 端口 目录扫描 http://10.129.155.171/dev/phpbash.min.php http://10.129.155.171/dev/phpbash.php 半交互式 shell 转向 交互式shell python -c import socket,subprocess,os;ssocket.socket(socket.AF_INET,socket.SOCK_STREAM);s.co…

dmdts连接kingbase8报错

dmdts连接kingbase报错 环境介绍1 人大金仓jdbc配置2 dmdts 人大金仓jdbc默认配置3 dmdts 修改jdbc配置4 达梦产品学习使用列表 环境介绍 dts版本 使用dmdts连接kingbase金仓数据库报错 无效的URL 对比jdbc连接串,修改配置解决 1 人大金仓jdbc配置 配置URL模版信息等 类名…

深度学习聚类再升级!新算法实现强悍性能,准确率超98%

深度聚类不仅继承了传统聚类算法的优点&#xff0c;在对高维和非线性数据的处理能力&#xff0c;以及自适应性和抗噪性方面也具有很大优势。 具体来说&#xff0c;结合深度学习的聚类算法通过利用深度神经网络的强大特征提取能力&#xff0c;自动学习和识别数据中的复杂结构和…

【小白专用24.5.30已验证】Composer安装php框架thinkPHP6的安装教程

一、框架介绍 1、框架简介和版本选择 Thinkphp是一种基于php的开源web应用程序开发框架ThinkPHP框架&#xff0c;是免费开源的、轻量级的、简单快速且敏捷的php框架。你可以免费使用TP框架&#xff0c;甚至可以将你的项目商用&#xff1b; ThinkPHP8.0 是目前框架正式版的最新版…

Spring 框架:Java 企业级开发的基石

文章目录 序言Spring 框架的核心概念Spring 框架的主要模块Spring Boot&#xff1a;简化 Spring 开发Spring Cloud&#xff1a;构建微服务架构实际案例分析结论 序言 Spring 框架自 2002 年发布以来&#xff0c;已经成为 Java 企业级开发的标准之一。它通过提供全面的基础设施…

家政预约小程序10公众号集成

目录 1 使用测试号3 工作流配置4 配置关注事件脚本5 注册开放平台6 获取公众号access_token6 实现关注业务逻辑总结 我们本次实战项目构建的相当于一个预约平台&#xff0c;既有家政企业&#xff0c;也有家政服务人员还有用户。不同的人员需要收到不同的消息&#xff0c;比如用…

11- Redis 中的 SDS 数据结构

字符串在 Redis 中是很常用的&#xff0c;键值对中的键是字符串类型&#xff0c;值有时也是字符串类型。 Redis 是用 C 语言实现的&#xff0c;但是它没有直接使用 C 语言的 char* 字符数组来实现字符串&#xff0c;而是自己封装了一个名为简单动态字符串&#xff08;simple d…

基于强化学习的控制率参数自主寻优

1.介绍 针对控制建模与设计场景中控制参数难以确定的普遍问题&#xff0c;提出了一种基于强化学习的控制律参数自主优化解决方案。该方案以客户设计的控制律模型为基础&#xff0c;根据自定义的控制性能指标&#xff0c;自主搜索并确定最优的、可状态依赖的控制参数组合。 可…

ToDesk提示会话数通道限制 - 解决方案及兑惠码分享

如果您最近在体验ToDesk这款远程操控工具时&#xff0c;遇到了提示信息告知“高速通道服务已到期”或“会话数受限”&#xff0c;这表明您本月享受的免费额度——即120小时的使用时间和最多300次的连接机会——已经耗尽。为了解锁无限制的使用时长与连接次数&#xff0c;建议您…

自动驾驶中的长尾问题

自动驾驶中的长尾问题 定义 长尾问题&#xff08;Long-Tail Problem&#xff09;是指在数据分布中&#xff0c;大部分的数据集中在少数类别上&#xff0c;而剩下的大多数类别却只有少量的数据。这种数据分布不平衡的现象在许多实际应用中广泛存在&#xff0c;特别是在自动驾驶…

20240531在飞凌的OK3588-C开发板上跑原厂的Buildroot测试USB摄像头

20240531在飞凌的OK3588-C开发板上跑原厂的Buildroot测试USB摄像头 2024/5/31 20:04 USB摄像头分辨率&#xff1a;1080p&#xff08;1920x1080&#xff09; 默认编译Buildroot的SDK即可点亮USB摄像头。v4l2-ctl --list-devices v4l2-ctl --list-formats-ext -d /dev/video74 …

双指针法 ( 快乐数 )

「快乐数」 定义为&#xff1a; 对于一个正整数&#xff0c;每一次将该数替换为它每个位置上的数字的平方和。然后重复这个过程直到这个数变为 1&#xff0c;也可能是 无限循环 但始终变不到 1。如果这个过程 结果为 1&#xff0c;那么这个数就是快乐数 编写一个算法来判断一个…

linux /www/server/cron内log文件占用空间过大,/www/server/cron是什么内容,/www/server/cron是否可以删除

linux服务器长期使用宝塔自带计划任务&#xff0c;计划任务执行记录占用服务器空间过大&#xff0c;导致服务器根目录爆满&#xff0c;需要长期排查并删除 /www/server/cron 占用空间过大问题处理 /www/server/cron是什么内容&#xff1f;/www/server/cron是否可以删除&#xf…