PAT Advanced 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 1 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 (≤, the total number of coins) and M (≤, 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 V1 and V2 (separated by a space) such that V1+V2=M and V1≤V2. If such a solution is not unique, output the one with the smallest V1. 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
#include <iostream>
#include <vector>
#define E 1000
using namespace std;
int main(){
int N,M,tmp;
cin>>N>>M;
int val[E]={};
while(N--){
scanf("%d",&tmp);
val[tmp]++;
}
bool flag=true;
for(int i=;i<E;i++){
if(val[i]!=&&val[M-i]!=&&(M-i)>=) {
if(i!=(M-i)||(i==(M-i)&&val[i]>)){
cout<<i<<" "<<(M-i);
flag=false;
break;
}
}
}
if(flag) cout<<"No Solution";
system("pause");
return ;
}
PAT Advanced 1048 Find Coins (25 分)的更多相关文章
- PAT 甲级 1048 Find Coins (25 分)(较简单,开个数组记录一下即可)
1048 Find Coins (25 分) Eva loves to collect coins from all over the universe, including some other ...
- PAT Advanced 1048 Find Coins (25) [Hash散列]
题目 Eva loves to collect coins from all over the universe, including some other planets like Mars. On ...
- 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 ...
- PAT Advanced 1020 Tree Traversals (25 分)
1020 Tree Traversals (25 分) Suppose that all the keys in a binary tree are distinct positive integ ...
- 【PAT甲级】1048 Find Coins (25 分)(二分)
题意: 输入两个正整数N和M(N<=10000,M<=1000),然后输入N个正整数(<=500),输出两个数字和恰好等于M的两个数(小的数字尽可能小且输出在前),如果没有输出&qu ...
- 1048 Find Coins (25分)
Eva loves to collect coins from all over the universe, including some other planets like Mars. One d ...
- PAT Advanced 1071 Speech Patterns (25 分)
People often have a preference among synonyms of the same word. For example, some may prefer "t ...
- PAT Advanced 1154 Vertex Coloring (25 分)
A proper vertex coloring is a labeling of the graph's vertices with colors such that no two vertices ...
- PAT Advanced 1085 Perfect Sequence (25) [⼆分,two pointers]
题目 Given a sequence of positive integers and another positive integer p. The sequence is said to be ...
随机推荐
- 浏览器端-W3School-HTML:HTML DOM Base 对象
ylbtech-浏览器端-W3School-HTML:HTML DOM Base 对象 1.返回顶部 1. HTML DOM Base 对象 Base 对象 Base 对象代表 HTML 的 base ...
- Python基本语法_函数_参数的多类型传值
前言 上一篇主要介绍了Python函数的参数类型,本篇继续学习Python函数多类型传值. 目录 前言 目录 软件环境 参数的多类型传值 向函数传递Tuple 向函数传递List 向函数传递Dicti ...
- python 2.7 error: Microsoft Visual C++ 9.0 is required
参考:https://stackoverflow.com/questions/43645519/microsoft-visual-c-9-0-is-required 解决方法: 下载并安装Micros ...
- Java学习之==>面向对象编程 Part2
一.封装 封装,即隐藏对象的属性和实现细节,仅对外公开接口,控制在程序中属性的读和修改的访问级别:将抽象得到的数据和行为(或功能)相结合,形成一个有机的整体,也就是将数据与操作数据的源代码进行有机的结 ...
- Report List 报表开发
1. Report List的输出定义 * ...NO STANDARD PAGE HEADING: 输出的报表不包含表头: * ...LINE-SIZE col : 输出的报表不包含表头: * .. ...
- mingw gcc 静态 static 编译 dav1d libdav1d.a
export CC=/mingw/bin/gcc export CXX=/mingw/bin/g++ meson --prefix "/usr/local" build --bui ...
- VirtualBox-5.2.8-121009-Win,虚拟机指令ifconfig不显示ip解决方法
- KinectFusion 介绍
原文链接 KinectFusion简介 KinectFusion是微软在2011年发表的一篇论文里提到的点云重建的方法,论文题目是:KinectFusion: Real-Time Dense Surf ...
- 【Python开发】【神经网络与深度学习】网络爬虫之python实现
一.网络爬虫的定义 网络爬虫,即Web Spider,是一个很形象的名字. 把互联网比喻成一个蜘蛛网,那么Spider就是在网上爬来爬去的蜘蛛. 网络蜘蛛是通过网页的链接地址来寻找网页的. 从网站某一 ...
- etcd api常用操作
如果需要使用v2 version api,启动etcd时候需要加入“ETCD_ENABLE_V2=true”参数,否则会报错“404 page not found” 获取etcd信息 版本信息 # c ...