当前位置:网站首页>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;
}
边栏推荐
- Billions of citizens' information has been leaked! Is there any "rescue" for data security on the public cloud?
- 实战模拟│JWT 登录认证
- 2021 CCPC 哈尔滨 I. Power and Zero(二进制 + 思维)
- 测试员的算法面试题-找众数
- maya灯建模
- 杰理之AD 系列 MIDI 功能说明【篇】
- VIM asynchronous problem
- 网件r7000梅林系统5g不稳定 5g信号经常掉线解决方法
- 搭建一个仪式感点满的网站,并内网穿透发布到公网 1/2
- y56.第三章 Kubernetes从入门到精通 -- 业务镜像版本升级及回滚(二九)
猜你喜欢
Huawei ENSP simulator configures DHCP for router
Advantages of RFID warehouse management system solution
torch.tensor和torch.Tensor的区别
6月“墨力原创作者计划”获奖名单公布!邀您共话国产数据库
UTF encoding and character set in golang
网件r7000梅林系统虚拟内存创建失败,提示USB磁盘读写速度不满足要求解决办法,有需要创建虚拟内存吗??
Huawei ENSP simulator realizes communication security (switch)
数十亿公民信息遭泄漏!公有云上的数据安全还有“救”吗?
华为模拟器ensp的路由配置以及连通测试
hash 表的概念及应用
随机推荐
Hwinfo hardware detection tool v7.26 green version
记一次重复造轮子(Obsidian 插件设置说明汉化)
hash 表的概念及应用
colResizable.js自动调整表格宽度插件
冰河的海报封面
c语言函数形参自增自减情况分析
杰理之AD 系列 MIDI 功能说明【篇】
WinCC7.5 SP1如何通过交叉索引来寻找变量及其位置?
FastDfs的快速入门,三分钟带你上传下载文件到云服务器
每日一题-LeetCode556-下一个更大元素III-字符串-双指针-next_permutation
实战模拟│JWT 登录认证
Actual combat simulation │ JWT login authentication
A quick start to fastdfs takes you three minutes to upload and download files to the ECS
IIC (STM32)
杰理之AD 系列 MIDI 功能说明【篇】
js 3D爆炸碎片图片切换js特效
接口設計時的一些建議
redis发布订阅的使用
heatmap.js图片热点热力图插件
插入排序,选择排序,冒泡排序