当前位置:网站首页>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.
关注博主不迷路,内容持续更新中.
边栏推荐
猜你喜欢
访问修饰符public、private、protected、default(默认不写) 区别
Makefile文件的编写(实例详解)
RNN神经网络适用于什么,RNN神经网络基本原理
传统图像特征提取方法:边缘与角点
C语言判断大小端存储问题
神经网络原理的简单介绍,神经网络原理及应用
The state machine control shift register multisim simulation in the process of state variables and state transition conditions don't match
ResNet网络结构详解、完整代码实现
带头双向循环链表的增删查改
深度神经网络主要模型,深度神经网络预测模型
随机推荐
P04 并发小球V1 V2.1
C语言判断大小端存储问题
【图形学】14 UnityShader语义(二)
【图形学】16 光照模型(一、理论与公式)
Variational Inference with Normalizing Flows
【Web】标准文档流
神经网络原理的简单介绍,神经网络原理及应用
RCNN目标检测原文理解
NVIDIA CUDA 高度并行处理器编程(八):并行模式:直方图计算
MySQL数据库和数据表的增删改查基础
通过使用fgets()统计文件的行号和使用fgets()/fputs()拷贝文件
P17 五子棋的实现4 悔棋功能
神经网络训练是什么意思,神经网络训练准确率
Lightning Sixteen Whip
Industry Research: Analysis of the Status and Prospects of the Pension Insurance Market in 2022
深度学习中的优化问题(Optimization)
深度学习基本实用工具
栈队列OJ题分享及讲解
Chemical Industry Research: Current Situation and Scale Analysis of Organic Silica Gel Market
C语言-文件中标准IO的常用函数总结