1048 Find Coins (25 分)

Eva loves to collect coins from all over the universe, including some other planets like Mars. One day she visited a universal shopping mall which could accept all kinds of coins as payments. However, there was a special requirement of the payment: for each bill, she could only use exactly two coins to pay the exact amount. Since she has as many as 10​5​​ coins with her, she definitely needs your help. You are supposed to tell her, for any given amount of money, whether or not she can find two coins to pay for it.

Input Specification:

Each input file contains one test case. For each case, the first line contains 2 positive numbers: N (≤10​5​​, the total number of coins) and M (≤10​3​​, the amount of money Eva has to pay). The second line contains N face values of the coins, which are all positive numbers no more than 500. All the numbers in a line are separated by a space.

Output Specification:

For each test case, print in one line the two face values V​1​​ and V​2​​ (separated by a space) such that V​1​​+V​2​​=M and V​1​​≤V​2​​. If such a solution is not unique, output the one with the smallest V​1​​. If there is no solution, output No Solution instead.

Sample Input 1:

8 15
1 2 8 7 2 4 11 15

Sample Output 1:

4 11

Sample Input 2:

7 14
1 8 7 2 4 11 15

Sample Output 2:

No Solution

分析:散列水题

 /**
 * Copyright(c)
 * All rights reserved.
 * Author : Mered1th
 * Date : 2019-02-25-21.22.03
 * Description : A1048
 */
 #include<cstdio>
 #include<cstring>
 #include<iostream>
 #include<cmath>
 #include<algorithm>
 #include<string>
 #include<unordered_set>
 #include<map>
 #include<vector>
 #include<set>
 using namespace std;
 ;
 };
 int main(){
 #ifdef ONLINE_JUDGE
 #else
     freopen("1.txt", "r", stdin);
 #endif
     int n,m,t;
     cin>>n>>m;
     ;i<n;i++){
         scanf("%d",&t);
         hashtable[t]++;
     }
     int i;
     ;i<=m/+;i++){
          &&hashtable[m-i]!=&&m-i!=i)||(m-i==i)&&hashtable[i]>=){
             printf("%d %d\n",i,m-i);
             ;
         }
     }
     +) printf("No Solution");
     ;
 }
分析:也可以用二分法求解, 也可以用双指针遍历
 /**
 * Copyright(c)
 * All rights reserved.
 * Author : Mered1th
 * Date : 2019-02-26-17.55.18
 * Description : A1048
 */
 #include<cstdio>
 #include<cstring>
 #include<iostream>
 #include<cmath>
 #include<algorithm>
 #include<string>
 #include<unordered_set>
 #include<map>
 #include<vector>
 #include<set>
 using namespace std;
 ;
 int a[maxn];
 int Bin(int left,int right,int key){
     int mid;
     while(left<=right){
         mid=(left+right)/;
         if(a[mid]==key) return mid;
         ;
         ;
     }
     ;
 }

 int main(){
 #ifdef ONLINE_JUDGE
 #else
     freopen("1.txt", "r", stdin);
 #endif
     int n,m,i;
     scanf("%d%d",&n,&m);
     ;i<n;i++){
         scanf("%d",&a[i]);
     }
     sort(a,a+n);
     ;i<n;i++){  //枚举左边界
         ,n-,m-a[i]);
         ){
             printf("%d %d\n",a[i],a[j]);
             break;
         }
     }
     if(i==n) printf("No Solution\n");
     ;
 }
 

1048 Find Coins (25 分)的更多相关文章

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

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

  2. PAT Advanced 1048 Find Coins (25 分)

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

  3. 1048 Find Coins (25分)

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

  4. 【PAT甲级】1048 Find Coins (25 分)(二分)

    题意: 输入两个正整数N和M(N<=10000,M<=1000),然后输入N个正整数(<=500),输出两个数字和恰好等于M的两个数(小的数字尽可能小且输出在前),如果没有输出&qu ...

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

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

  6. 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 ...

  7. 1048. Find Coins (25)

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

  8. PAT Advanced 1048 Find Coins (25) [Hash散列]

    题目 Eva loves to collect coins from all over the universe, including some other planets like Mars. On ...

  9. PAT (Advanced Level) 1048. Find Coins (25)

    先对序列排序,然后枚举较小值,二分较大值. #include<iostream> #include<cstring> #include<cmath> #includ ...

  10. PAT甲题题解-1048. Find Coins (25)-水

    给n,m以及n个硬币 问,是否存在两个硬币面值v1+v2=m 因为面值不会超过500,所以实际上最多500个不同的硬币而已 #include <iostream> #include < ...

随机推荐

  1. [转]数据库更新(Update语句)查询

    2011-03-27 10:40:11| 分类: Database |举报|字号 订阅原文出自:http://blog.csdn.net/ylnjust02/archive/2005/12/10/54 ...

  2. springboot跨域请求

      首页 所有文章 资讯 Web 架构 基础技术 书籍 教程 Java小组 工具资源 SpringBoot | 番外:使用小技巧合集 2018/09/17 | 分类: 基础技术 | 0 条评论 | 标 ...

  3. ssh key建立后不能clone问题

    在建立了ssh密钥对之后,要将私钥添加,公钥key添加到gitlab的ssh keys里. 添加成功后,这个时候,你可以clone了! 总结:如果是遇到重复输入密码的情况,可能是ssh-key,的私钥 ...

  4. 炸掉你的城堡!(pygame獾兔大战)

    代码修改bug,添加注释等,獾的速度加快之后很难-- git地址: https://github.com/Jailman/blowupyrcastle.git 游戏资源使用了文章中附带的下载,原版文章 ...

  5. webstrom git 版本控制

    1.配置 2.用法

  6. Centos编译Unix网络编程(第三版)卷1的源代码

    测试环境:Centos 1)在shell中输入./configure然后按回车(注意先让configure有执行权限 chomd 777 configure) 2)依次进入lib.libfree.li ...

  7. HDU 2853 && HDU 3315

    http://acm.hdu.edu.cn/showproblem.php?pid=2853 题意:给一个n-m二分图,边权用一个n*m的矩阵表示,给出初始匹配,求二分图完美匹配相比初始匹配改变了几条 ...

  8. hacking a friend's Linux buzzer driver in OK335xS

    /**************************************************************************** * hacking a friend's L ...

  9. Vec3b类型数据确定颜色通道

    前言 这几天实习生测试一张图像的三个通道分别是什么颜色,使用的是Vec3b类型,然后发现了一个有意思的点.. 测试过程 先创建了一定大小的数据, Mat test( , , CV_8UC3, Scal ...

  10. Mongodb $setOnInsert操作符 和upsert:true

    upsert:true:如果要更新的文档不存在的话会插入一条新的记录 $setOnInsert操作符会将指定的值赋值给指定的字段,如果要更新的文档存在那么$setOnInsert操作符不做任何处理: ...