当前位置:网站首页>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;
}边栏推荐
- Automatic generation of interface automatic test cases by actual operation
- HMS Core 统一扫码服务
- Hwinfo hardware detection tool v7.26 green version
- Poster cover of glacier
- What are the functional modules of RFID warehouse management system solution
- Gobang go to work fishing tools can be LAN / man-machine
- Roast B station charges, is it because it has no money?
- Go notes (3) usage of go language FMT package
- Remember to build wheels repeatedly at one time (the setting instructions of obsidian plug-in are translated into Chinese)
- MySQL --- 数据库查询 - 聚合函数的使用、聚合查询、分组查询
猜你喜欢

FastDfs的快速入门,三分钟带你上传下载文件到云服务器

分析伦敦银走势图的技巧

LeetCode+ 81 - 85 单调栈专题

网件r7000梅林系统虚拟内存创建失败,提示USB磁盘读写速度不满足要求解决办法,有需要创建虚拟内存吗??

Pytorch---使用Pytorch实现LinkNet进行语义分割

Quelques suggestions pour la conception de l'interface

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??

How does win11 search for wireless displays? Win11 method of finding wireless display device

多模輸入事件分發機制詳解

JS卡牌样式倒计时天数
随机推荐
js 3D爆炸碎片图片切换js特效
What if the computer page cannot be full screen? The solution of win11 page cannot be full screen
Browser render page pass
c语言函数形参自增自减情况分析
LeetCode 8. 字符串转换整数 (atoi)
How to solve the problem that win11 cannot write the value to the registry key?
PermissionError: [Errno 13] Permission denied: ‘data.csv‘
哈希表、哈希函数、布隆过滤器、一致性哈希
What if the WiFi of win11 system always drops? Solution of WiFi total drop in win11 system
福昕PDF编辑器v10.1.8绿色版
测试员的算法面试题-找众数
Go notes (1) go language introduction and characteristics
hash 表的概念及应用
Poster cover of glacier
Pytorch---使用Pytorch实现LinkNet进行语义分割
What if the brightness of win11 is locked? Solution to win11 brightness locking
五子棋 上班摸鱼工具 可局域网/人机
go defer的使用说明
uniapp 富文本编辑器使用
Roast B station charges, is it because it has no money?