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. MyEclipse WebSphere开发教程:安装和更新WebSphere 6.1, JAX-WS, EJB 3.0(二)

    你开学,我放价!MyEclipse线上狂欢继续!火热开启中>> [MyEclipse最新版下载] MyEclipse支持Java EE技术(如JAX-WS和EJB 3.0),它们以功能包的 ...

  2. 和不安全的Android说再见,Google为它添加新铠甲

    伴随着最近被曝出的Heartbleed漏洞,安全问题再次成为网络上的热点话题.虽然Android的安全性并没有外界传言的那样脆弱,但Google还是在继续为其增加防护措施.根据Android官方博客的 ...

  3. php 值引用

    1.值传递 复制代码 代码如下: <?php function exam($var1){ $var1++: echo "In Exam:" . $var1 . "& ...

  4. 使用 Git & Repo 下载代码

    客户端安装 Git 安装 git,gitk 网络连接正常的情况下: $ sudo apt-get install git-core gitk git-gui 不能上网,有.deb安装包的,请执行: $ ...

  5. Python 文件修改

    # 需求: 把好人换成sb # 必须: # 1. 先从文件中读取内容 # 2. 把要修改的内容进行修改 # 3. 把修改好的内容写人一个新文件 # 4. 删除掉原来的文件 # 5. 把新文件重命名成原 ...

  6. Swift中获取系统语言

    //en-US zh-HK zh-TW zh-Hans-US var lng:String { let userDefault = NSUserDefaults.standardUserDefault ...

  7. Jmeter系列培训(1)--开山篇

    ​       一直以来,我们不断分享,有的人喜欢,也有的人不喜欢,这都没什么,喜欢的点个赞,留个言,不喜欢的就不看好了,今天我们继续,关于jmeter我们分享了很多工作遇到的问题的解决方案,但是很多 ...

  8. 在 Windows 10 中开启移动 WLAN 热点

    本文将介绍如何在 Windows 10 中开启移动 Wi-Fi 热点. This post is written in multiple languages. Please select yours: ...

  9. 2018-2019-2 《网络对抗技术》Kali安装 Week1 20165212

    2018-2019-2 <网络对抗技术>Kali安装 Week1 20165212 1.完成安装linux kali和vm tools 装的第三遍成功安装.前面两次镜像文件不行,没驱动(网 ...

  10. day35 python学习GIL解释器锁

    二 GIL介绍 GIL本质就是一把互斥锁,既然是互斥锁,所有互斥锁的本质都一样,都是将并发运行变成串行,以此来控制同一时间内共享数据只能被一个任务所修改,进而保证数据安全. 可以肯定的一点是:保护不同 ...