Codeforces Round 889 (Div. 2)(视频讲解A——D)

news2024/7/2 3:50:22

文章目录

  • A Dalton the Teacher
  • B Longest Divisors Interval
  • C2 Dual (hard Version)
  • D Earn or Unlock

Codeforces Round 889 (Div. 2)(视频讲解A——D)
在这里插入图片描述

A Dalton the Teacher

#include<bits/stdc++.h>
#define endl '\n'
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N = 1e5 + 10;

void solve()
{
	int n;
	cin >> n;
	vector<int>a(n + 1);
	int ans = 0;
	for(int i = 1; i <= n; i ++)
	{
		cin >> a[i];
		if(a[i] == i)
			ans ++;
	}
	cout << (ans + 1) / 2 << endl;
}	

signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin >> t;
	while(t--)
	solve();
}

B Longest Divisors Interval

#include<bits/stdc++.h>
#define endl '\n'
#define INF 0x3f3f3f3f
#define int long long
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N = 1e5 + 10;

void solve()
{
	int n;
	cin >> n;
	if(n <= 2)
	{
		cout << n << endl;
		return;
	}
	for(int i = 1; i <= n; i ++)
	{
		if((n % i) != 0)
		{
			cout << i - 1 << endl;
			return;
		}
	}
}

signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin >> t;
	while(t--)
	solve();
}

C2 Dual (hard Version)

#include<bits/stdc++.h>
#define endl '\n'
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N = 1e5 + 10;

void add_1(vector<int>&a, vector<pii>&ans)
{
	for(int i = 0; i < a.size() - 1; i ++)
	{
		a[i + 1] += a[i];
		ans.push_back({i + 1, i});
	}
	cout << ans.size() << endl;
	for(auto [a, b] : ans)
		cout << a + 1 << " " << b + 1 << endl;
	return;
}

void add_2(vector<int>&a, vector<pii>&ans)
{
	for(int i = a.size() - 1; i >= 1; i --)
	{
		a[i - 1] += a[i];
		ans.push_back({i - 1, i});
	}
	cout << ans.size() << endl;
	for(auto [a, b]: ans)
		cout << a + 1 << " " << b + 1 << endl;
	return;
}

void solve()
{
	int n;
	cin >> n;
	vector<int>a(n);
	int p_max = 0, p_min = 0;
	int cnt_1 = 0, cnt_2 = 0;
	vector<pii>ans;
	for(int i = 0; i < n; i ++)
	{
		cin >> a[i];
		if(a[p_max] < a[i])
			p_max = i;
		if(a[p_min] > a[i])
			p_min = i;
		if(a[i] < 0)
			cnt_2 ++;
		if(a[i] > 0)
			cnt_1 ++;
	}
	
	if(a[p_min] >= 0)
	{
		add_1(a, ans);
		return;
	}
	
	if(a[p_max] <= 0)
	{
		add_2(a, ans);
		return;
	}

	if(abs(a[p_max]) >= abs(a[p_min]))
	{
		if(cnt_2 <= 12)
		{
			for(int i = 0; i < n; i ++)
			{
				if(a[i] < 0)
				{
					a[i] += a[p_max];
					ans.push_back({i, p_max});
				}
			}
			add_1(a, ans);
		}
		else
		{
			for(int i = 0; i < 5; i ++)
			{
				if(abs(a[p_min]) >= abs(a[p_max]))
					break;
				ans.push_back({p_min, p_min});
				a[p_min] += a[p_min];
			}

			for(int i = 0; i < n; i ++)
			{
				if(a[i] > 0)
				{
					a[i] += a[p_min];
					ans.push_back({i, p_min});
				}
			}
			add_2(a, ans);
		}
	}
	else
	{
		if(cnt_1 <= 12)
		{
			for(int i = 0; i < n; i ++)
			{
				if(a[i] > 0)
				{
					a[i] += a[p_min];
					ans.push_back({i, p_min});
				}
			}
			add_2(a, ans);
		}
		else
		{
			for(int i = 0; i < 5; i ++)
			{
				if(abs(a[p_max]) >= abs(a[p_min]))
					break;	
				a[p_max] += a[p_max];
				ans.push_back({p_max, p_max});
			}
			for(int i = 0; i < n; i ++)
			{
				if(a[i] < 0)
				{
					a[i] += a[p_max];
					ans.push_back({i, p_max});
				}
			}
			add_1(a, ans);
		}
	}


}

signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin >> t;
	while(t--)
	solve();
}

D Earn or Unlock

#include<bits/stdc++.h>
#define endl '\n'
#define INF 0x3f3f3f3f
#define int long long
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
const int N = 2e5 + 10;
bitset<N>f;
int n, a[N], sum[N];
void solve()
{
	cin >> n;
	for(int i = 1; i <= n; i ++)
		cin >> a[i];
	for(int i = 1; i <= 2 * n; i ++)
		sum[i] = sum[i - 1] + a[i];

	int ans = 0;
	f[1] = 1;
	for(int i = 1; i <= 2 * n; i ++)
	{
		f |= (f << a[i]);
		if(f[i])
		{
			ans = max(sum[i] - i + 1, ans);
			f[i] = 0;
		}
	}
	cout << ans << endl;
}

signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	solve();
}

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

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

相关文章

自定义MVC增删改查

目录 mymvcdemo是自定义mvc框架的使用示例 1.1 实体类 1.2 dao方法 1.3 写Service / biz 三层架构 1.4 建action 相当于selvert 1.5 con连接MySQL 8.0 版本 1.6 配置文件 XML 1.7 主界面布局 1.8 增加界面布局 1.9 写tld配置文件 2.0 注意架包 我是已经打包好的 mymv…

Leetcode-每日一题【剑指 Offer 53 - I. 在排序数组中查找数字 I】

题目 统计一个数字在排序数组中出现的次数。 示例 1: 输入: nums [5,7,7,8,8,10], target 8输出: 2 示例 2: 输入: nums [5,7,7,8,8,10], target 6输出: 0 提示&#xff1a; 0 < nums.length < 105-109 < nums[i] < 109nums 是一个非递减数组-109 < targe…

Java课题笔记~ MyBatis入门

一、ORM框架 当今企业级应用的开发环境中&#xff0c;对象和关系数据是业务实体的两种表现形式。业务实体在内存中表现为对象&#xff0c;在数据库中变现为关系数据。当采用面向对象的方法编写程序时&#xff0c;一旦需要访问数据库&#xff0c;就需要回到关系数据的访问方式&…

软件测评中心测试流程是怎样的?CMA、CNAS软件测试报告出具

软件测评中心是一个专门负责进行软件评估、测试和审查等工作的机构。在软件测评中心中&#xff0c;软件测试流程是按照一系列固定的步骤和流程进行的&#xff0c;以确保测试工作的全面性、系统性和规范性。 1、需求分析&#xff1a;在软件测评过程中&#xff0c;首先需要对软件…

经典病毒上线流量分析-Lokibot

一、概述 Lokibot于2015年面世&#xff0c;持续活跃至今&#xff0c;是一种高度危险且隐匿的恶意软件&#xff0c;旨在窃取受害主机的敏感信息&#xff0c;包括存储的密码、浏览器登录凭据以及加密货币钱包等&#xff0c;并将这些信息上送到远程C2服务器上。本文将重点针对Lok…

穷举深搜暴搜回溯剪枝(1)

一)全排列: 46. 全排列 - 力扣&#xff08;LeetCode&#xff09; 1)先画出决策树: 越详细越好&#xff0c;就是我们在进行暴力枚举这道题的过程中&#xff0c;如何不重不漏地将所有的情况全部枚举到&#xff0c;把这个思想历程给画下来&#xff0c;就可以了&#xff0c;把每一步…

【css】外边距margin

外边距中有一个属性值比较有意思&#xff1a;inherit 值&#xff0c;继承父类的属性。 <!DOCTYPE html> <html> <head> <style> div {border: 1px solid red;margin-left: 100px; }p.ex1 {margin-left: inherit; } </style> </head> <…

[React]生命周期

前言 学习React&#xff0c;生命周期很重要&#xff0c;我们了解完生命周期的各个组件&#xff0c;对写高性能组件会有很大的帮助. Ract生命周期 React 生命周期分为三种状态 1. 初始化 2.更新 3.销毁 初始化 1、getDefaultProps() 设置默认的props&#xff0c;也可以用duf…

实验笔记之——Windows下的Android环境开发搭建

好久一段时间没有进行Android开发了&#xff0c;最新在用的电脑也没有了Android studio了。为此&#xff0c;本博文记录一下最近重新搭建Android开发的过程。本博文仅为本人学习记录用&#xff08;**别看&#xff09; 之前博客也对配置Android做过记录 Android学习笔记之——A…

Mybatis高级映射及动态加载及逆向工程

目录 1.多对一 2.一对多 3.⼀对多延迟加载 4.逆向工程 1.多对一 多种⽅式&#xff0c;常⻅的包括三种&#xff1a; 第⼀种⽅式&#xff1a;⼀条SQL语句&#xff0c;级联属性映射。第⼆种⽅式&#xff1a;⼀条SQL语句&#xff0c;association。第三种⽅式&#xff1a;两条SQ…

虹科案例 | PLC如何应用于建筑的3D打印?

客户&#xff1a;Rebuild 合作伙伴&#xff1a;ASTOR 应用&#xff1a;用于建筑的大尺寸3D打印 应用产品&#xff1a;3D混凝土打印机 &#xff08;一&#xff09;应用背景 自从20世纪80年代以来&#xff0c;增材制造技术&#xff08;即3D打印&#xff09;不断发展。大部分3D打印…

flannel的三种常见模式分析

概述 大家接触flannel这种网络模式大多数可能都是从k8s中知道的&#xff0c;初始使用很少去深入了解它&#xff0c;毕竟使用它其实是很简单的。但是有时候会出现奇奇怪怪的网络问题&#xff0c;这个时候就需要我们更深入了解一下flannel这种网络模式。 Flannel是CoreOS开源的&…

【BASH】回顾与知识点梳理(四)

【BASH】回顾与知识点梳理 四 四. Bash Shell 的操作环境4.1 路径与指令搜寻顺序4.2 bash 的进站与欢迎讯息&#xff1a; /etc/issue, /etc/motd4.3 bash 的环境配置文件login与non-login shell/etc/profile (login shell 才会读)~/.bash_profile (login shell 才会读)source &…

Spark2x原理剖析(一)

一、简介 Spark是基于内存的分布式计算框架。在迭代计算的场景下&#xff0c;数据处理过程中的数据可以存储在内存中&#xff0c;提供了比MapReduce高10到100倍的计算能力。Spark可以使用HDFS作为底层存储&#xff0c;使用户能够快速地从MapReduce切换到Spark计算平台上去。Sp…

【数据结构】二叉树、二叉搜索树、平衡二叉树、红黑树、B树、B+树

概述 二叉树&#xff08;Binary Tree&#xff09;&#xff1a;每个节点最多有两个子节点&#xff08;左子节点和右子节点&#xff09;&#xff0c;没有限制节点的顺序。特点是简单直观&#xff0c;易于实现&#xff0c;但查找效率较低。 二叉搜索树&#xff08;Binary Search…

【严重】PowerJob<=4.3.3 远程代码执行漏洞

漏洞描述 PowerJob 是一款开源的分布式任务调度框架。 由于 PowerJob 未对网关进行鉴权&#xff0c;4.3.3 及之前版本中&#xff0c;未经授权的攻击者可向 /instance/detail 端点发送恶意构造的 instanceId 参数远程执行任意代码。 漏洞名称 PowerJob<4.3.3 远程代码执行漏…

集团MySQL的酒店管理系统

酒店管理系统 概述 基于Spring Spring MVC MyBatis的酒店管理系统&#xff0c;主要实现酒店客房的预定、入住以及结账等功能。使用Maven进行包管理。 用户端主要功能包括&#xff1a; 登录注册、客房预订、客房评论&#xff08;编写评论和查看评论&#xff09; 后台管理主要…

如何理解PID?

1 理解PID 先说结论&#xff1a;调整开关量让反馈更接近目标。 这里拿水龙头打比方&#xff0c;我们想控制水龙头的出水量为一半&#xff0c;这里就涉及两个关键量&#xff0c;阀门和出水量&#xff1b;阀门&#xff0c;即上面说的开关量&#xff1b;出水量即反馈&#xff1b…

postman和jmeter的区别何在?

小伙伴们大家好呀&#xff0c;前段时间笔者做了一个小调查&#xff0c;发现软件测试行业做功能测试和接口测试的人相对比较多。在测试工作中&#xff0c;有高手&#xff0c;自然也会有小白&#xff0c;但有一点我们无法否认&#xff0c;就是每一个高手都是从小白开始的&#xf…

推荐50个超实用的 Chrome 扩展,建议收藏!

今天来分享 50 个超实用的 Chrome 浏览器扩展&#xff01; JSON Viewer Pro JSON Viewer Pro 用于可视化JSON文件。其核心功能包括&#xff1a; 支持将JSON数据进行格式化&#xff0c;并使用属性或者图表进行展示&#xff1b;使用面包屑深入遍历 JSON 属性&#xff1b;在输入…