Two point
来源:互联网 发布:广州app商城源码 编辑:程序博客网 时间:2024/06/06 07:23
所谓Two point ,是用两个指针,在两个数组中走,来求一些最大值
前提是两个数组升序(其实是有序)
我们用两个数组来求c,d的前缀最大值
然后运用Two point 来求最大值
代码如下
#include <cstdio>#include <iostream>using namespace std;int a[9999],b[9999];int max1[9999],max2[9999];int main(){ int n,p; scanf("%d%d",&n,&p); for(int i=1;i<=n;i++) scanf("%d",&a[i]); for(int i=1;i<=n;i++) scanf("%d",&b[i]); for(int i=1,x;i<=n;i++) { scanf("%d",&x); if(x>max1[i-1]) max1[i]=x; else max1[i]=max1[i-1]; } for(int i=1,x;i<=n;i++) { scanf("%d",&x); if(x>max2[i-1]) max2[i]=x; else max2[i]=max2[i-1]; } int ans=0; int t=n; for(int i=1;i<=n;i++) { while(a[i]+b[t]>p&&t>=1) t--; if(!t) break; ans=max(ans,max1[i]+max2[t]); } printf("%d",ans); return 0; }
阅读全文
1 0
- two point
- Two point
- 【Hackerrank】Find the merge point of two joined linked lists
- hdu 5288 OO’s Sequence(two point + rmq)
- LeetCode Two Point & Array Problem 两点问题汇总
- Least-Squares Fitting of Two 3-D Point Sets
- 6-14 Add Two Polynomials(20 point(s))
- Point
- Point
- point
- Point
- point
- Point
- Find the first intersection of two lists (if the two list are merged at some point)
- CodeForces 293E Close Vertices(点分治+Two Point法+树状数组)
- 6-18 Two Stacks In One Array(20 point(s))
- Appliation Loader上传App 莫名其妙的错误 The CFBundleExecutable of two bundles may not point to the same file.
- Point to Point Communication
- G
- UVA1601TheMorningAfterHalloween
- LeetCode- 125. Valid Palindrome
- LeetCode-541. Reverse String II
- Java集合框架(3)——HashMap
- Two point
- LeetCode-345. Reverse Vowels of a String
- k`th number
- LeetCode-344. Reverse String
- PLSQL Developer 12 64位下载 v12.0.4汉化中文版
- LeetCode-521. Longest Uncommon Subsequence I
- LeetCode-551. Student Attendance Record I
- LeetCode- 125. Valid Palindrome
- 环境变量