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 ...
随机推荐
- leetcode-easy-string-387 First Unique Character in a String
mycode 24.42% class Solution: def firstUniqChar(self, s: str) -> int: dic = {} for i in range(le ...
- Oracle9i的详细安装与卸载步骤(有图解)
Oracle9i的安装和卸载详解 本章将以Windows操作系统为例讲述Oracle9i数据库的安装 ...
- Android 多分辨率与不同语言适配
一.适配不同国家语言 智能手机系统设置里各国语言的选项,然后我们项目里可以通过资源目录实现适配语言.我们知道工程的根目录有个res/的目录,res/下有一个资源类型的目录,其中有个values/str ...
- [HTML辅助方法-Html.Raw()的简单应用]
Html.Raw(); 当我们使用 文本编辑器,存入到数据库中的数据会带 html 标签,如果我们需要在前台显示存入时的相同样式,不输出为带有html标签的字符串 ,不通过富文本显示的话,可以通过ht ...
- 浏览器端-W3School-JavaScript:JavaScript RegExp 对象
ylbtech-浏览器端-W3School-JavaScript:JavaScript RegExp 对象 1.返回顶部 1. JavaScript RegExp 对象 RegExp 对象 RegEx ...
- Selenium 2自动化测试实战4(引用模块)
一.模组1.模组也叫类库或模块,引用模块 在python中,通过import….或from….import….的方式引用模块,下面引用time模块 import time print (time.ct ...
- 阶段3 2.Spring_10.Spring中事务控制_8 spring基于纯注解的声明式事务控制
新建项目 把之前项目src下的内容全部复制过来 pom.xml内复制过来 开始配置 新建一个config的包,然后再新建配置文件类SpringConfiguration @Configuration这 ...
- RL - 001- 入门
https://www.freecodecamp.org/news/an-introduction-to-reinforcement-learning-4339519de419/ https://gi ...
- Python学习之面向对象(一)
第六章 面向对象 6.1 面向对象的初识 6.1.1 什么是面向对象 面向过程式编程: 好处:出色的完成所有的需求 坏处:凡是更改或者增加一条需求,可能整个项目都随之改变 面向对象式编程: 类 ...
- Nginx配置反向代理与负载均衡
Nginx的upstream目前支持的分配算法: 1.round-robin 轮询1:1轮流处理请求(默认) 每个请求按时间顺序逐一分配到不同的应用服务器,如果应用服务器down掉,自动剔除,剩下的继 ...