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 ...
随机推荐
- Python之变量以及类型
为了更充分的利用内存空间以及更有效率的管理内存,变量是有不同的类型的,如下所示: 怎样知道一个变量的类型呢? 在python中,只要定义了一个变量,而且它有数据,那么它的类型就已经确定了,不需要咱们开 ...
- python文件读写和异常
1,文本文件 普通打开 f.open f.close def main(): f = None try: f = open('致橡树.txt', 'r', encoding='utf-8') prin ...
- RedHat 5下安装gcc编译环境的具体步骤
RedHat 5下安装gcc编译环境的具体步骤 在RHEL5系统中默认不安装linux系统中的开发编译环境(gcc),此软件包安装时依赖其他包较多 在以前使用RHEL4时可以通过如下命令安装: rpm ...
- Python新手最容易犯的十大错误
1. 忘记写冒号 在 if.elif.else.for.while.class.def 语句后面忘记添加“:” if spam == 42 print('Hello!') 2. 误用 “=” 做等值比 ...
- golang基础学习-MongoDB使用
1.系统环境 Golang:go version go1.10.3 darwin/amd64 OS:MacOS MongoDB: version: 3.4.4 2.Golang使用MongoDB 使用 ...
- Cocos2d-X网络编程(5) 使用Rapidjson解析数据
Json基础及28种c++解析库性能对比 JSON 概念和特点: JSON 指的是 JavaScript 对象表示法(JavaScript Object Notation) JSON ...
- Python学习之UDP版socket&SocketServer
7.6 基于UDP的socket 无连接的,不必与对方建立连接,而是直接把数据发送给对方: 适用于一次传输销量数据结构,可靠性不高的应用环境,因为其传输速率快 # 服务端 import socket ...
- mariadb数据库增删改查
1.常用数据类型 1)整数:int, bit 2)小数:decimal #decimal(5,2)表示共有五位数,保留两位小数 3)字符串:varchar, char 4)日期时间:date, ...
- 【VS开发】使用WinPcap编程(3)——设置过滤器
设置过滤器要用到两个函数,一个是pcap_compile(),另一个是pcao_setfilter().他们的函数原型如下所示: int pcap_compile (pcap_t *p, struct ...
- 【VS开发】【图像处理】ISP图像传感器处理器基础
1 前言 做为拍照手机的核心模块之一,camera sensor效果的调整,涉及到众多的参数,如果对基本的光学原理及sensor软/硬件对图像处理的原理能有深入的理解和把握的话,对我们的 ...