当前位置:网站首页>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 功能说明【篇】
torch. Tensor and torch The difference between tensor
render函数与虚拟dom
c语言函数形参自增自减情况分析
Huawei ENSP simulator enables devices of multiple routers to access each other
Billions of citizens' information has been leaked! Is there any "rescue" for data security on the public cloud?
Huawei ENSP simulator realizes communication security (switch)
Hwinfo hardware detection tool v7.26 green version
偷窃他人漏洞报告变卖成副业,漏洞赏金平台出“内鬼”
【1200. 最小绝对差】
随机推荐
IIC (STM32)
华为模拟器ensp的路由配置以及连通测试
测试用例 (TC)
RFID仓库管理系统解决方案有哪些功能模块
网件r7000梅林系统虚拟内存创建失败,提示USB磁盘读写速度不满足要求解决办法,有需要创建虚拟内存吗??
LeetCode 8. String conversion integer (ATOI)
Can be displayed in CAD but not displayed in print
redis缓存
网件r7000梅林系统5g不稳定 5g信号经常掉线解决方法
为什么说不变模式可以提高性能
async await 在map中使用
Routing configuration and connectivity test of Huawei simulator ENSP
每日一题-LeetCode1200-最小绝对差-数组-排序
福昕PDF编辑器v10.1.8绿色版
扩展你的KUBECTL功能
Huawei ENSP simulator layer 3 switch
RFID仓储管理系统解决方案的优点
The concept and application of hash table
Huawei ENSP simulator configures DHCP for router
Day24:文件系统