poj 2366 Sacrament of the sum 尺取法的灵活运用
来源:互联网 发布:太极越狱mac 编辑:程序博客网 时间:2024/06/12 22:59
题意:
给一个升序数列和一个降序数列,判读是否能从中各取一个数,使他们的和为10000.
思路:
尺取法是一种求最小区间的算法,通过设置不前移的指针p和不后移的指针q来求满足某个条件的最小区间。类似地,设置两个不前移的指针p,q,可设计O(n)算法。
代码:
//poj 2366//sep9#include<iostream>using namespace std;const int maxN=40000;int a[maxN],b[maxN];int main(){int n,m;while(scanf("%d",&n)==1){int i;for(i=0;i<n;++i)scanf("%d",&a[i]);scanf("%d",&m);for(i=0;i<m;++i)scanf("%d",&b[i]);int p=0,q=0;int ans=0;while(p<n&&q<m){if(a[p]+b[q]==10000){ans=1;break;}else if(a[p]+b[q]<10000)++p;else++q;}printf("%s\n",ans==0?"NO":"YES");}return 0;}
0 0
- poj 2366 Sacrament of the sum 尺取法的灵活运用
- poj 2366 Sacrament of the sum
- POJ - 2366 Sacrament of the sum
- poj 2366 Sacrament of the sum
- POJ 2366 Sacrament of the sum
- POJ 2366 Sacrament of the sum
- POJ 2366 Sacrament of the sum
- day2 POJ 2366 Sacrament of the sum
- poj 2366 Sacrament of the sum
- poj 2366 Sacrament of the sum
- POJ 2366 Sacrament of the sum(二分查找)
- POJ 2366 (URAL 1021)Sacrament of the Sum
- acm解题报告 POJ 2366 Sacrament of the sum
- POJ - 2366 Sacrament of the sum 二分查找
- Sacrament of the sum
- 1021. Sacrament of the Sum
- C - Sacrament of the sum
- 【二分查找】[POJ2366]Sacrament of the sum
- 小兔的棋盘
- hdu 1054 Strategic Game 最小点覆盖
- 基于Arm 的linux 的启动分析
- 关于手机和各种pad的定位
- EOJ2562
- poj 2366 Sacrament of the sum 尺取法的灵活运用
- 数据挖掘过程模型研究
- 晶振两端串联和并联电阻的租用
- hadoop学习5-HDFS API学习
- DICOM医学图像处理:DIMSE消息发送与接收“大同小异”之DCMTK fo-dicom mDCM
- primary key与unique
- 学习笔记1-Metro UI
- CheckBox的API
- 我的高精度加法模板