当前位置:网站首页>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;
}
边栏推荐
- 【1200. 最小绝对差】
- Flet tutorial 06 basic introduction to textbutton (tutorial includes source code)
- [Shenbo introduction] VI How to contact your favorite doctoral tutor
- 字节测试工程师十年经验直击UI 自动化测试痛点
- Summary of the mistakes in the use of qpainter in QT gobang man-machine game
- 网络命名空间
- 【服务器数据恢复】某品牌服务器存储raid5数据恢复案例
- 阿里云国际版CDN的优势
- FastDfs的快速入门,三分钟带你上传下载文件到云服务器
- Advantages of semantic tags and block level inline elements
猜你喜欢
FastDfs的快速入门,三分钟带你上传下载文件到云服务器
Summary of the mistakes in the use of qpainter in QT gobang man-machine game
Leetcode+ 81 - 85 monotone stack topic
哈希表、哈希函数、布隆过滤器、一致性哈希
c语言函数形参自增自减情况分析
【观察】联想:3X(1+N)智慧办公解决方案,释放办公生产力“乘数效应”
伦敦银走势图分析的新方法
HWiNFO硬件检测工具v7.26绿色版
Solution of 5g unstable 5g signal often dropped in NetWare r7000 Merlin system
LeetCode+ 81 - 85 单调栈专题
随机推荐
What if the win11 shared file cannot be opened? The solution of win11 shared file cannot be opened
LeetCode 8. 字符串转换整数 (atoi)
Google colab踩坑
How to solve the problem that win11 cannot write the value to the registry key?
伦敦银走势图分析的新方法
HWiNFO硬件检测工具v7.26绿色版
How does wincc7.5 SP1 find variables and their positions through cross indexing?
MySQL --- 数据库查询 - 聚合函数的使用、聚合查询、分组查询
Poster cover of glacier
五子棋 上班摸鱼工具 可局域网/人机
【1200. 最小绝对差】
How does win11 search for wireless displays? Win11 method of finding wireless display device
Jmeter 之压测入门
华为ensp模拟器 给路由器配置DHCP
[1200. Minimum absolute difference]
colResizable.js自动调整表格宽度插件
网件r7000梅林系统虚拟内存创建失败,提示USB磁盘读写速度不满足要求解决办法,有需要创建虚拟内存吗??
VIM asynchronous problem
【解决方案】PaddlePaddle 2.x调用静态图模式
What if the brightness of win11 is locked? Solution to win11 brightness locking