题意:略

思路:two pointers思想,简单

先对数字序列进行排序,然后定义两个指针left和right,初始状态low=0,high=n-1。当a[low]+a[high] > M时,high向左移动;当a[low]+a[high] < M时,left向右移动。

代码:

#include <cstdio>
#include <algorithm>
using namespace std;
;
int value[N];
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    ;i<n;i++)
        scanf("%d",&value[i]);
    sort(value,value+n);
    ,high=n-;
    while(low<high){
        if(value[low]+value[high]==m) break;
        else if(value[low]+value[high]>m) high--;
        else low++;
    }
    if(low==high) printf("No Solution\n");
    else printf("%d %d\n",value[low],value[high]);
    ;
}

1048 Find Coins的更多相关文章

  1. PAT 解题报告 1048. Find Coins (25)

    1048. Find Coins (25) Eva loves to collect coins from all over the universe, including some other pl ...

  2. 1048 Find Coins (25 分)

    1048 Find Coins (25 分) Eva loves to collect coins from all over the universe, including some other p ...

  3. PAT甲 1048. Find Coins (25) 2016-09-09 23:15 29人阅读 评论(0) 收藏

    1048. Find Coins (25) 时间限制 50 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Eva loves t ...

  4. PAT 1048 Find Coins[比较]

    1048 Find Coins (25 分) Eva loves to collect coins from all over the universe, including some other p ...

  5. PAT 甲级 1048 Find Coins (25 分)(较简单,开个数组记录一下即可)

    1048 Find Coins (25 分)   Eva loves to collect coins from all over the universe, including some other ...

  6. 1048. Find Coins (25)

    时间限制 50 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Eva loves to collect coins from a ...

  7. PAT 1048. Find Coins

    two sum题目,算是贪婪吧 #include <cstdio> #include <cstdlib> #include <vector> #include &l ...

  8. PAT 甲级 1048 Find Coins

    https://pintia.cn/problem-sets/994805342720868352/problems/994805432256675840 Eva loves to collect c ...

  9. PTA(Advanced Level)1048.Find Coins

    Eva loves to collect coins from all over the universe, including some other planets like Mars. One d ...

  10. PAT Advanced 1048 Find Coins (25 分)

    Eva loves to collect coins from all over the universe, including some other planets like Mars. One d ...

随机推荐

  1. thrift安装及常见问题

    一.安装thrift (macOS / Linux) 1. 下载thrift0.10.0源码 https://github.com/apache/thrift/releases/tag/0.10.0 ...

  2. JavaScript 打印控件

    JavaScript 打印控件 github地址 https://github.com/DoersGuild/jQuery.print 使用前需要引入jQuery $("#mapDiv&qu ...

  3. spring的AOP动态代理--JDK代理和CGLIB代理区分以及注意事项

    大家都知道AOP使用了代理模式,本文主要介绍两个代理模式怎么设置以及区别,对原文一些内容进行了引用后加入了自己的理解和更深入的阐述:   一.JDK代理和CGLIB代理的底层实现区别* JDK代理只能 ...

  4. python学习笔记(matplotlib下载安装)

    最近博主在找工作换新环境.昨天电话面试中问到python中threading模块进行接口性能测试的时候.如何生成性能测试报告 我现在还停留在打印在屏幕中.所以今天想着是否可以生成相应的性能测试报告 首 ...

  5. tracecaller.cs

    #region Utility #if TRACE private const string Traceformat = "\"{0}\",\"{1:yyyy- ...

  6. MS Project 如何删除前置任务

  7. [6644] 02 Apr 23:11:58.976 # Creating Server TCP listening socket *:6379: bind: No such file or directory

    redis报错: [6644] 02 Apr 23:11:58.976 # Creating Server TCP listening socket *:6379: bind: No such fil ...

  8. List排序共通代码

    此共通方法可以根据特定字段进行排序 package com.gomecar.index.common.utils; import java.lang.reflect.Method; import ja ...

  9. Django的model查询操作 与 查询性能优化

    Django的model查询操作 与 查询性能优化 1 如何 在做ORM查询时 查看SQl的执行情况 (1) 最底层的 django.db.connection 在 django shell 中使用 ...

  10. Wix是什么?

    Wix是Windows Installer XML的简称,其通过类XML文件格式来指定了用于创建Windows Installer安装包数据库的元素.关于Wix的详细介绍,http://wixtool ...