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

Codeforces Round #822 (Div. 2) 补题 (A、B、C)

Codeforces Round #822 Div. 2

    • A - Select Three Sticks (800)
    • B - Bright, Nice, Brilliant (800)
    • C - Removing Smallest Multiples (1200)
    • D Slime Escape


参考的大佬的题解

A - Select Three Sticks (800)

简单思维,一看数据范围直接三重循环(要是省赛有这么松的数据范围就好了)

#include<bits/stdc++.h>

using namespace std;

#define int long long 

const int N = 1e5 + 10;

int n, T;
int a[N];

signed main()
{
	cin>>T;
	while(T -- ){
		cin>>n;
		int ans = 1e9;
		map<int, int>mp;
		int f = 0;   
		for(int i = 1; i <= n; i ++ ){
			cin>>a[i];
			mp[a[i]] ++ ;
			f = max(f, mp[a[i]]);
		}
		
		if(f >= 3){
			cout<<0<<endl;
		}
		else{
			for(int i = 1; i <= n; i ++ ){
				for(int j = 1; j <= n; j ++ ){
					for(int k = 1; k <= n; k ++ ){
						if(i != j && j != k && k != i){
							ans = min(ans, abs(a[i] - a[j]) + abs(a[k] - a[i]));
						}
					}
				}
			}
			cout<<ans<<endl;
		}
	}
	return 0;
}

B - Bright, Nice, Brilliant (800)

简单思维,要认清能到达一个房间的房间都有那些,之后发现只有塔的两侧亮了才符合要求

#include<bits/stdc++.h>

using namespace std;

const int N = 610;

int n, m;
int a[N][N];
int T;

int main()
{
	cin>>T;
	while(T -- ){
		cin>>n;
		for(int i = 1; i <= n; i ++ ){
			for(int j = 1; j <= i; j ++ ){
				if(j == 1) a[i][j] = 1;
				else if(j == i) a[i][j] = 1;
				else{
					a[i][j] = 0;
				}
			}
		}
		
		for(int i = 1; i <= n; i ++ ){
			for(int j = 1; j <= i; j ++ ){
				cout<<a[i][j]<<' ';
			}
			cout<<endl;
		}
	}
	return 0;
}

C - Removing Smallest Multiples (1200)

自己想了个解法没有写出来,缘由是一些数没有覆盖到,果然功力还是差些火候,还是大佬的写法妙啊
请添加图片描述

#include<bits/stdc++.h>

using namespace std;

#define int long long 

const int N = 1e6 + 10;

int n, m;
int a[N];
int T;
bool del[N], p[N];
string str;

void solve(){
	int ans = 0;  //记录答案
	cin>>n;
	cin>>str;
	
	for(int i = 0; i <= n; i ++ ){
		del[i] = false;
		p[i] = false;
	}
	
	for(int i = 0; i < n; i ++ ){
		if(str[i] == '0') del[i + 1] = true;
		else p[i + 1] = true;
	}

	for(int i = 1; i <= n; i ++ ){
		for(int j = i; j <= n; j += i){
			if(del[j]){  //如果这个数可以删 
				ans += i;  //累加答案  
				del[j] = false;  //标记这个数已经删过了,不能再删 
			} 
			else{  //到这里有两种情况,一种是这个数j不应该删,但i的最小公倍数还没删,循环还可以继续向上找i的可以删的最小公倍数 
				   //另一种是这个数不应该删,i的再向上的最小公倍数不能再用i花费,就可以进入到下面的if中 
				if(p[j]) break;
			}
		}
	}
	cout<<ans<<endl;
}

signed main()
{
	cin>>T;
	while(T -- ){
		solve(); 
	}
	return 0;
}

D Slime Escape

相关文章:

  • 【初阶与进阶C++详解】第十六篇:AVL树-平衡搜索二叉树(定义+插入+旋转+验证)
  • 去除多重共线性的5种方法,你学废了嘛?
  • Verilog的奇技淫巧[更新中]
  • 被CTO推荐的SQL总结
  • 第八章 时序检查(下)
  • Android 10 低内存应用白名单和应用保活
  • 攻防演练中攻击队需要的安全技能第二篇
  • C#的File 类使用说明
  • 零基础能学大数据技术吗?学完能找到工作吗?
  • 实时即未来,车联网项目之远程诊断实时故障分析【七】
  • 《SpringBoot篇》10.JPQL超详细介绍与JPA命名规则
  • 【Android-实战】1、Room 使用 Flow 和 collect() 监听数据库的变化、动态更新页面
  • python字符串应用
  • asp.net高校网上评教信息系统VS开发sqlserver数据库web结构c#编程计算机网页项目
  • 暂退法dropout----详解与分析(多层感知机)
  • [译]Python中的类属性与实例属性的区别
  • 《剑指offer》分解让复杂问题更简单
  • Consul Config 使用Git做版本控制的实现
  • ESLint简单操作
  • Python打包系统简单入门
  • Spark学习笔记之相关记录
  • 解析带emoji和链接的聊天系统消息
  • 理解IaaS, PaaS, SaaS等云模型 (Cloud Models)
  • 线上 python http server profile 实践
  • 在electron中实现跨域请求,无需更改服务器端设置
  • Oracle Portal 11g Diagnostics using Remote Diagnostic Agent (RDA) [ID 1059805.
  • 函数计算新功能-----支持C#函数
  • ​html.parser --- 简单的 HTML 和 XHTML 解析器​
  • ​queue --- 一个同步的队列类​
  • ​软考-高级-系统架构设计师教程(清华第2版)【第9章 软件可靠性基础知识(P320~344)-思维导图】​
  • # Python csv、xlsx、json、二进制(MP3) 文件读写基本使用
  • # 再次尝试 连接失败_无线WiFi无法连接到网络怎么办【解决方法】
  • #android不同版本废弃api,新api。
  • #if和#ifdef区别
  • #Lua:Lua调用C++生成的DLL库
  • (06)金属布线——为半导体注入生命的连接
  • (BFS)hdoj2377-Bus Pass
  • (echarts)echarts使用时重新加载数据之前的数据存留在图上的问题
  • (Redis使用系列) SpirngBoot中关于Redis的值的各种方式的存储与取出 三
  • (阿里云万网)-域名注册购买实名流程
  • (二)斐波那契Fabonacci函数
  • (分布式缓存)Redis持久化
  • (附源码)计算机毕业设计SSM保险客户管理系统
  • (三) prometheus + grafana + alertmanager 配置Redis监控
  • (三分钟了解debug)SLAM研究方向-Debug总结
  • (转)使用VMware vSphere标准交换机设置网络连接
  • (转载)深入super,看Python如何解决钻石继承难题
  • *上位机的定义
  • ./configure,make,make install的作用
  • .bat批处理(六):替换字符串中匹配的子串
  • .htaccess配置重写url引擎
  • .L0CK3D来袭:如何保护您的数据免受致命攻击
  • .Net IOC框架入门之一 Unity
  • .NET 编写一个可以异步等待循环中任何一个部分的 Awaiter
  • .NET/C# 使用反射注册事件