当前位置:网站首页>2021 CCPC Harbin B. magical subsequence (thinking question)
2021 CCPC Harbin B. magical subsequence (thinking question)
2022-07-04 21:21:00 【GHOSTANDBREAD】
Problem - B - Codeforces
Ideas :
From front to back, find the maximum length of the sum of two . It can be discontinuous , But it must be in the order from front to back . It can be found that the range of each number is [1,100], Not much , Is a breakthrough , The sum of two numbers sum The range is [2,200], The traverse sum In every case . When the number being traversed and the number appearing before are added together, it is equal to sum when ,res+=2, Then set the previous number to be unusable . If the sum of the numbers being traversed sum The difference has not appeared before , Then set the number to be usable , Continue traversing backwards .
Code :
#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;
}
边栏推荐
- 杰理之AD 系列 MIDI 功能说明【篇】
- 【微信小程序】协同工作与发布
- Hwinfo hardware detection tool v7.26 green version
- Configuration of DNS server of Huawei ENSP simulator
- What are the functional modules of RFID warehouse management system solution
- 【申博攻略】六.如何联系心仪的博导
- Y56. Chapter III kubernetes from entry to proficiency -- business image version upgrade and rollback (29)
- 【Try to Hack】宽字节注入
- Huawei ENSP simulator layer 3 switch
- How does wincc7.5 SP1 find variables and their positions through cross indexing?
猜你喜欢
Some suggestions for interface design
js 3D爆炸碎片图片切换js特效
The concept and application of hash table
Hands on deep learning (III) -- convolutional neural network CNN
WinCC7.5 SP1如何通过交叉索引来寻找变量及其位置?
网件r7000梅林系统虚拟内存创建失败,提示USB磁盘读写速度不满足要求解决办法,有需要创建虚拟内存吗??
测试员的算法面试题-找众数
偷窃他人漏洞报告变卖成副业,漏洞赏金平台出“内鬼”
B站视频 声音很小——解决办法
colResizable.js自动调整表格宽度插件
随机推荐
Ten years' experience of byte test engineer directly hits the pain point of UI automation test
多模输入事件分发机制详解
扩展你的KUBECTL功能
Day24: file system
杰理之AD 系列 MIDI 功能说明【篇】
UTF encoding and character set in golang
Nmap scan
五子棋 上班摸鱼工具 可局域网/人机
吐槽 B 站收费,是怪它没钱么?
torch.tensor和torch.Tensor的区别
LeetCode 8. 字符串转换整数 (atoi)
MySQL - database query - use of aggregate function, aggregate query, grouping query
Y56. Chapter III kubernetes from entry to proficiency -- business image version upgrade and rollback (29)
6月“墨力原创作者计划”获奖名单公布!邀您共话国产数据库
Routing configuration and connectivity test of Huawei simulator ENSP
colResizable.js自动调整表格宽度插件
MySQL --- 数据库查询 - 聚合函数的使用、聚合查询、分组查询
Roast B station charges, is it because it has no money?
heatmap.js图片热点热力图插件
Explication détaillée du mécanisme de distribution des événements d'entrée multimodes