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 ...
随机推荐
- PHP CI框架数据库常用操作
例子 <?php defined('BASEPATH') OR exit('No direct script access allowed'); class Menu extends CI_Co ...
- leetcode 137单词接龙
直接层序遍历,结果有部分测试样例超时: class Solution { public: int ladderLength(string beginWord, string endWord, vect ...
- python - 函数any() 和 all() 的区别
转自:https://www.cnblogs.com/nulige/p/6128816.html any()与all()函数的区别: any是任意,而all是全部. 版本:该函数适用于2.5以上版本, ...
- JAVA 内存的那些事
(转载)固然Java屏蔽了一下内存细节,但是有时候,了解一下这些常识还是有好处的,特别是一些口试,总是盯着这些玩意不放手. JVM启动以后,会分配两类内存区域,一类用于开发职员使用,比如保存一些变量, ...
- 【HTML5】---【HTML5提供的一些新的标签用法以及和HTML 4的区别】
HTML 5 是一个新的网络标准,目标在于取代现有的 HTML 4.01, XHTML 1.0 and DOM Level 2 HTML 标准.它希望能够减少浏览器对于需要插件的丰富性网络应用服务(p ...
- 【HANA系列】SAP ECLIPSE中创建ABAP项目失败原因解析
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[HANA系列]SAP ECLIPSE中创建AB ...
- python线程池--threadpool
在爬虫时,有时候解析获得了很多图片或视频地址时,如果一个个下载完成再去下载另一个,这样执行效率太慢了,此时就可用到线程池threadpool,使用基本步骤如下: 1.定于任务函数 2.创建线程池,定义 ...
- 修改了Mysql密码后连接不到服务且无报错信息解决方法以及修改密码方法
安装MYSQL后更改了root的密码后用 net start mysql 启动时出现:无法启动,无报错信息 使用以下命令:1.管理员方式cmd进入mysql安装目录的bin目录下2.执行命令:mysq ...
- 【神经网络与深度学习】leveldb的实现原理
郑重声明:本篇博客是自己学习 Leveldb 实现原理时参考了郎格科技系列博客整理的,原文地址:http://www.samecity.com/blog/Index.asp?SortID=12,只是为 ...
- Win10删除右键菜单快捷键方法
打开注册表,找到HKEY_CLASSES_ROOT\Directory\Background路径,删除对应的快捷方式即可