当前位置:网站首页>acwing 63rd weekly match【2022.08.06】
acwing 63rd weekly match【2022.08.06】
2022-08-08 07:04:00 【Java technology made easy】
acwing第63场周赛【2022.08.06】
一、4503. 数对数量
1. 题目描述

2. 思路分析
签到题,Just brute force the pairs of integers for the three conditions(x, y)的个数即可.
3. 代码实现
#include <bits/stdc++.h>
using namespace std;
int main()
{
int a, b, n;
int res = 0;
cin >> a >> b >> n;
for (int i = 0; i <= a; i ++ )
{
for (int j = 0; j <= b; j ++ )
if (i + j == n) res ++;
}
cout << res << endl;
return 0;
}
二、4504. 字符串消除
1. 题目描述

2. 思路分析
- Use the stack for maintenance,First push the first character onto the stack,依次枚举每个字符
- If the stack is not empty and the character is the same as the top element of the stack,则栈顶元素出栈,并且
ans++; - Otherwise push the character onto the stack;
- If the stack is not empty and the character is the same as the top element of the stack,则栈顶元素出栈,并且
- 如果
ans为奇数,则先手必赢;如果ans为偶数,则先手必输.
3. 代码实现
#include <bits/stdc++.h>
#include <cstring>
using namespace std;
const int N = 1e5 + 10;
char a[N];
stack<char> stk;
int main()
{
int res = 0;
scanf("%s", a);
stk.push(a[0]);
for (int i = 1; i < strlen(a); i ++ )
{
if (stk.size() > 0 && a[i] == stk.top())
{
stk.pop();
res ++;
}
else
{
stk.push(a[i]);
}
}
if (res % 2 == 0) cout << "No" << endl;
else cout << "Yes" << endl;
return 0;
}
三、4505. 最大子集
1. 题目描述

2. 思路分析
提示:The maximum possible size of a collection is 3,The smallest size will not be less than1,The case of three numbers is an arithmetic progression.
- First put all the numbers into the hash set;
- 枚举最小值,以及公差(最多30种公差),找到长度3the longest sequence within ;
- 剪枝:找到长度为3The sequence ends the algorithm directly.
3. 代码实现
#include <bits/stdc++.h>
using namespace std;
const int N = 200010, M = 1999997, INF = 0x3f3f3f3f;
int n;
int q[N], h[M];
int find(int x)
{
int t = (x % M + M) % M;
while (h[t] != INF && h[t] != x)
if ( ++ t == M)
t = 0;
return t;
}
int main()
{
scanf("%d", &n);
for (int i = 0; i < n; i ++ ) scanf("%d", &q[i]);
sort(q, q + n);
memset(h, 0x3f, sizeof h);
int res[3], s[3];
int rt = 0, st = 0;
for (int i = 0; i < n; i ++ )
{
for (int j = 0; j <= 30; j ++ )
{
int d = 1 << j;
s[0] = q[i], st = 1;
for (int k = 1; k <= 2; k ++ )
{
int x = q[i] - d * k;
if (h[find(x)] == INF) break;
s[st ++ ] = x;
}
if (rt < st)
{
rt = st;
memcpy(res, s, sizeof s);
if (rt == 3) break;
}
}
if (rt == 3) break;
h[find(q[i])] = q[i];
}
printf("%d\n", rt);
for (int i = 0; i < rt; i ++ )
printf("%d ", res[i]);
return 0;
}
四、周赛总结
This week onlyac了前两道,The third question is too complicated to think aboutac出来,Fight for the next weekak.
关注博主不迷路,内容持续更新中.
边栏推荐
- 最详细的Vivado安装教程
- C# Unicode (Universal Code) text conversion
- 线程P01——进程 并发 并行 线程的使用
- Vivado安装—Xilinx design tool already exists for 2019.1,specify a different program program group entr
- 文件IO实现图片的加密操作
- ESP32 温湿度和气体传感器驱动
- Error日志 ERROR: Failed building wheel for jsonnet
- [Unity] GPU动画实现(五)——渲染GPU动画
- 如何使用conda,pip安装、更新、查看和卸载重装Pytorch?
- P03 线程安全 synchronized Lock
猜你喜欢

顺序循环队列的创建和基本应用

Rose essential oil market research: the current market output value exceeds 2.3 billion yuan, and the market demand gap is about 10%

Stack queue OJ question sharing and explanation

【嵌入式Linux】SQLite数据库

MongoDB的介绍与特点

Accelerate CNNs from Three Dimensions: A Comprehensive Pruning Framework详解

jupyter notebook添加目录

Unity—ParticleSystem (particle system) and Animator (animation state machine) batch manager

Markdown语法快速入门(以Topyra为例)

中序表达式转为后序表达式
随机推荐
正则爬取豆瓣Top250数据存储到CSV文件(6行代码)
CSDN21天学习挑战赛之插入排序
深度神经网络主要模型,深度神经网络预测模型
[Unity] GPU动画实现(四)——生成动画数据
略解损失函数
[Unity] GPU动画实现(一)——介绍
神经网络原理的简单介绍,神经网络原理及应用
P22 美颜相机——引入动态数组,优化重绘
[Unity] 自定义日志系统 解决Unity Log的痛点
YOLO v1 原理到代码(一)
Unity—ParticleSystem (particle system) and Animator (animation state machine) batch manager
用户管理 用户的增删改查 切换用户 用户组 用户组相关文件
【图形学】16 光照模型(一、理论与公式)
P02 线程的用途
rhcsa第二天
uniapp微信小程序订阅消息发送服务通知--超详细
MongoDB常用命令整理
SCIERC语料格式解读
人工神经网络的工作原理,神经网络的基本原理
MongoDB的介绍与特点