当前位置:网站首页>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;
}边栏推荐
- Poster cover of glacier
- 网件r7000梅林系统虚拟内存创建失败,提示USB磁盘读写速度不满足要求解决办法,有需要创建虚拟内存吗??
- GVM use
- 【服务器数据恢复】某品牌服务器存储raid5数据恢复案例
- 华为ensp模拟器 DNS服务器的配置
- MySQL --- 数据库查询 - 聚合函数的使用、聚合查询、分组查询
- 基于OpenCV haarcascades的对象检测
- Some suggestions for interface design
- [1200. Différence absolue minimale]
- From automation to digital twins, what can Tupo do?
猜你喜欢

How does the computer save web pages to the desktop for use

Hands on deep learning (III) -- convolutional neural network CNN

PS vertical English and digital text how to change direction (vertical display)

【1200. 最小絕對差】

网络命名空间

PS竖排英文和数字文字怎么改变方向(变竖直显示)

五子棋 上班摸鱼工具 可局域网/人机

Flet tutorial 06 basic introduction to textbutton (tutorial includes source code)

【1200. 最小绝对差】

偷窃他人漏洞报告变卖成副业,漏洞赏金平台出“内鬼”
随机推荐
Poster cover of glacier
Automatic insertion of captions in word
ACM组合计数入门
torch.tensor和torch.Tensor的区别
【微服务|SCG】Predicate的使用
Nmap scan
软件开发过中的采购
接口設計時的一些建議
MySQL --- 数据库查询 - 聚合函数的使用、聚合查询、分组查询
UTF encoding and character set in golang
冰河的海报封面
What if the brightness of win11 is locked? Solution to win11 brightness locking
Idea restore default shortcut key
测试用例 (TC)
【观察】联想:3X(1+N)智慧办公解决方案,释放办公生产力“乘数效应”
插入排序,选择排序,冒泡排序
Explication détaillée du mécanisme de distribution des événements d'entrée multimodes
HWiNFO硬件检测工具v7.26绿色版
Pytorch---使用Pytorch实现LinkNet进行语义分割
面对同样复杂的测试任务为什么大老很快能梳理解决方案,阿里十年测试工程师道出其中的技巧