pat1048. Find Coins (25)
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 105 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 (<=105, the total number of coins) and M(<=103, 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<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<queue>
#include<vector>
#include<cmath>
#include<string>
#include<map>
#include<set>
using namespace std;
int line[];
int main(){
//freopen("D:\\INPUT.txt","r",stdin);
int n,m;
scanf("%d %d",&n,&m);
int i,j;
for(i=;i<n;i++){
scanf("%d",&line[i]);
}
sort(line,line+n); /*for(i=0;i<n;i++){
cout<<i<<" "<<line[i]<<endl;
}*/ i=;
j=n-;
while(i<j){
if(line[i]+line[j]>m){
j--;
continue;
}
if(line[i]+line[j]<m){
i++;
continue;
}
break;
}
if(i<j){
printf("%d %d\n",line[i],line[j]);
}
else{
printf("No Solution\n");
}
return ;
}
pat1048. 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 pl ...
- PAT1048:Find Coins
1048. Find Coins (25) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Eva loves ...
- 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 甲级 1048 Find Coins (25 分)(较简单,开个数组记录一下即可)
1048 Find Coins (25 分) Eva loves to collect coins from all over the universe, including some other ...
- 1048. Find Coins (25)
时间限制 50 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Eva loves to collect coins from a ...
- PAT1048. Find Coins(01背包问题动态规划解法)
问题描述: Eva loves to collect coins from all over the universe, including some other planets like Mars. ...
- PAT Advanced 1048 Find Coins (25 分)
Eva loves to collect coins from all over the universe, including some other planets like Mars. One d ...
- PAT Advanced 1048 Find Coins (25) [Hash散列]
题目 Eva loves to collect coins from all over the universe, including some other planets like Mars. On ...
- 1048 Find Coins (25分)
Eva loves to collect coins from all over the universe, including some other planets like Mars. One d ...
随机推荐
- Android proguard代码混淆
为什么要代码混淆? Android的安装文件是apk格式.APK是AndroidPackage的缩写.是由android sdk编译的工程打包生成的安装程序文件. Apk其实是zip文件,但是后缀名被 ...
- CHTools-OC版本目录介绍
1.CHOCBase 这里主要讲的是Objective-C语言的基础语法. 2.CHViewControllers 3.CHNS类 5.CHUI类 这里是CHUI类的集合,用于处理界面显示,其中包含部 ...
- 为什么使用docker
为什么要使用Docker? 作为一种新兴的虚拟化方式,Docker跟传统的虚拟化方式相比具有众多的优势. 更高效的利用系统资源 由于容器不需要进行硬件虚拟及运行完整操作系统等额外开销,Docker对系 ...
- apache-jmeter-3.1的简单压力测试使用方法
压力测试工具LoadRunner是收费的,而且操作复杂.作为开发人员当然是用apache提供的jmeter,免费容易上手. jmeter下载地址http://jmeter.apache.org/首先下 ...
- Mysql(Linux服务器)root用户密码忘记重置方法
MySQL是非常常见的开源数据库,使用者众多,若是不小心忘记了安装在服务器的mysql密码,无法登陆,应该如何重置呢?方法很简单,现在和大家分享下.(系统环境:CentOs 6.5 软件:Mysql ...
- 解决织梦手机网站M文件夹动态游览不生成html
今天的做手机网站的时候,发现dede织梦M文件夹下会生成index.html.对于手机网站来说,太麻烦了.每次更新手机网站首页都要把index.html删除掉重新生成. 然而织梦不支持手机网站首页动态 ...
- 最短路【bzoj2464】: 中山市选[2009]小明的游戏
2464: 中山市选[2009]小明的游戏 Description 小明最近喜欢玩一个游戏.给定一个n * m的棋盘,上面有两种格子#和@.游戏的规则很简单:给定一个起始位置和一个目标位置,小明每一步 ...
- (转)接口自动化测试之http请求实践总结
一.接口测试的基本思路 1.确定要测试接口的请求类型.接口是get请求还是post请求. 2.确定接口的参数.需要传输的参数有哪些,类型分别是什么,都有哪些要求等. 3.按照参数要求构造请求需要的参数 ...
- python模块之urllib
python文档官网地址:https://docs.python.org/3.6/library/urllib.html?highlight=urllib urllib 是一个收集以下模块以处理URL ...
- component: resolve => require(['../pages/home.vue'], resolve)
component: resolve => require(['../pages/home.vue'], resolve) vue 路由的懒加载 import Vue from 'vue' im ...