博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
1044. Shopping in Mars
阅读量:4640 次
发布时间:2019-06-09

本文共 1158 字,大约阅读时间需要 3 分钟。

Two points (proposed to be low and high )both start to point the begining of the array,

If current subsequence sum is more than the need sum,low++;

If current subsequence sum is less than the need sum,high++;

If current subsequence sum is equal to  the need sum,print the current subsequence;

At the end,if we can't find the corresponding result is equal to the need sum,just find the minimum sum(minimumMax) of the subsequence which is more than the need sum.

Then,search the subsequence which is equal to minimumMax as previously described.

// 1044. Shopping in Mars.cpp: 主项目文件。#include "stdafx.h"#include 
const int INF=0x7fffffff;const int N=100003;int diamond[N];int arrNum,needSum;bool selectChain(){ bool tag=false; int low=0,high=0,minimumMax=INF,curSum=diamond[low]; while(low
<=high){ if(curSum>needSum){ if(curSum
needSum){ low++,high++; curSum=diamond[low]; continue; } if(curSum==needSum){ tag=true; printf("%d-%d\n",low+1,high+1); curSum=curSum-diamond[low++]+diamond[++high]; } else if(curSum

转载于:https://www.cnblogs.com/cjweffort/archive/2013/03/13/3374847.html

你可能感兴趣的文章
oracle, group by, having, where
查看>>
⑥python模块初识、pyc和PyCodeObject
查看>>
object-c中管理文件和目录:NSFileManager使用方法
查看>>
Kibana:分析及可视化日志文件
查看>>
nodejs pm2使用
查看>>
cocos2d-x 3.10 PageView BUG
查看>>
装饰器的基本使用:用户登录
查看>>
CSS选择器总结
查看>>
mysql中sql语句
查看>>
head/tail实现
查看>>
sql语句的各种模糊查询语句
查看>>
vlc 学习网
查看>>
Python20-Day05
查看>>
Real World Haskell 第七章 I/O
查看>>
C#操作OFFICE一(EXCEL)
查看>>
【js操作url参数】获取指定url参数值、取指定url参数并转为json对象
查看>>
ABAP 程序间的调用
查看>>
移动端单屏解决方案
查看>>
web渗透测试基本步骤
查看>>
使用Struts2标签遍历集合
查看>>