当前位置:网站首页>2021 CCPC 哈尔滨 B. Magical Subsequence(思维题)
2021 CCPC 哈尔滨 B. Magical Subsequence(思维题)
2022-07-04 20:13:00 【GHOSTANDBREAD】
Problem - B - Codeforces
思路:
从前往后找寻两两之和一样的最大长度。可以不连续,但是一定是按从前往后的顺序。可以发现每个数的范围是[1,100],范围不大,是一个突破口,两数相加的和sum的范围是[2,200],则遍历sum的每一种情况。当正在遍历的数和之前出现的数相加等于sum时,res+=2,然后将前面的数设置为不能使用。如果正在遍历的数和sum的差在前面没有出现过,则把该数设置为可以使用,继续向后遍历。
代码:
#include<iostream>
#include<cstring>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int vis[205];
int n, maxn;
int main() {
scanf("%d", &n);
vector<int> a(n);
for(int i = 0; i < n; i ++) scanf("%d", &a[i]);
int maxn = -1;
for(int sum = 2; sum <= 200; sum ++) {
int res = 0;
memset(vis, 0, sizeof vis);
for(int i = 0; i < n; i ++) {
if(a[i] < sum) {
if(vis[sum - a[i]]) {
res += 2;
memset(vis, 0, sizeof vis);
} else {
vis[a[i]] = 1;
}
}
}
maxn = max(maxn, res);
}
printf("%d", maxn);
return 0;
}
边栏推荐
- Implementation of redis distributed lock
- 【服务器数据恢复】某品牌服务器存储raid5数据恢复案例
- 杰理之AD 系列 MIDI 功能说明【篇】
- 插入排序,选择排序,冒泡排序
- Alibaba testers use UI automated testing to achieve element positioning
- Flet tutorial 04 basic introduction to filledtonalbutton (tutorial includes source code)
- Quelques suggestions pour la conception de l'interface
- Google colab踩坑
- ACM组合计数入门
- Advantages of semantic tags and block level inline elements
猜你喜欢
Render function and virtual DOM
Pytorch---使用Pytorch实现LinkNet进行语义分割
Idea configuration standard notes
华为ensp模拟器实现通信安全(交换机)
admas零件名重复
Summary of the mistakes in the use of qpainter in QT gobang man-machine game
Golang中UTF编码和字符集
【服务器数据恢复】某品牌服务器存储raid5数据恢复案例
What if the win11 shared file cannot be opened? The solution of win11 shared file cannot be opened
网件r7000梅林系统5g不稳定 5g信号经常掉线解决方法
随机推荐
华为ensp模拟器 实现多个路由器的设备可以相互访问
From automation to digital twins, what can Tupo do?
NetWare r7000 Merlin system virtual memory creation failed, prompting that the USB disk reading and writing speed does not meet the requirements. Solution, is it necessary to create virtual memory??
实战模拟│JWT 登录认证
In the face of the same complex test task, why can the elder sort out the solution quickly? Ali's ten-year test engineers showed their skills
黄金k线图中的三角形有几种?
[solution] paddlepaddle 2 X call static graph mode
五子棋 上班摸鱼工具 可局域网/人机
The concept and application of hash table
Detailed explanation of multi-mode input event distribution mechanism
华为模拟器ensp常用命令
面对同样复杂的测试任务为什么大老很快能梳理解决方案,阿里十年测试工程师道出其中的技巧
Procurement in software development
【申博攻略】六.如何联系心仪的博导
__init__() missing 2 required positional arguments 不易查明的继承错误
Jekins initialization password not found or not found
Pytorch---使用Pytorch实现LinkNet进行语义分割
Go language notes (4) go common management commands
Record the online bug solving list (unfinished to be continued 7/4)
Redis:Redis配置文件相关配置、Redis的持久化