题意:略

思路: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. Java多线程 - 线程组

    Java使用ThreadGroup来表示线程组,用以对一批线程进行分类管理. Java允许程序对线程组直接进行控制,对线程组的控制相当于同时控制这批线程: 用户创建的所有线程都属于指定线程组,如果程序 ...

  2. Dynamo概述

    Dynamo 是Amazon提供的一款高可用的分布式Key-Value存储系统,其满足可伸缩性.可用性.可靠性. CAP原理满足:通过一致性哈希满足P,用复制满足A,用对象版本与向量时钟满足C.用牺牲 ...

  3. 扫描局域网中Gogs服务器(ruby)

    scanGogs.rb #!/usr/bin/env ruby require 'net/http' require 'thread' require 'english' # config CONFI ...

  4. https://www.adminsub.net/tcp-udp-port-finder/14000 ——查找tcp端口对应的服务 可以看某些端口是否让恶意软件开启

    效果: TCP/UDP Port FinderPort number or name:Enter port number (e.g. 21), service (e.g. ssh, ftp) or t ...

  5. C/C++开发android应用

    (转自:http://blog.csdn.net/srplab1/article/details/7617963) 在某些情况下,比如原来与很多c/c++的代码, 可能希望采用c/c++编写andro ...

  6. LeetCode OJ:Insertion Sort List (插入排序链表)

    Sort a linked list using insertion sort. 用插入排序来排序一个list,额, 我写的好麻烦啊, debug了好久,至少提交了5次...写吐了快,先贴代码,写的也 ...

  7. 对servlet的 再总结 (精品)

    首先 可以通过URL 在浏览器端访问servlet,因为在web.xml中配置了URL与类全名的 映射. 我们初学时,很容易分不清,浏览器端访问的 是jsp页面还是servlet.  其实当我们用浏览 ...

  8. eclipse 不能启动虚拟机

    在eclipse文件下有个eclipse.ini文件打开它.现在如果没有-vm 这个参数那么就在最后新起一行写上 -vm+空格+参数 参数是你安装的jdk目录比如我的 -vm d:/java/jdk1 ...

  9. Android的方法和属性(2)

    1.RadioButton(单选按钮) 嵌入到RsdioGroup中实现单选效果 android:checkedButton="radio的id值" int getCheckedR ...

  10. Ubuntu下安装为知笔记

    之前在Windows下用的是有道云笔记,但是后来开始习惯使用Linux开发,有道云官方并没有提供Ubuntu的版本,所以权衡之下,选择了为知笔记,安装步骤: sudo add-apt-reposito ...