1048. Find Coins (25)

时间限制
50 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

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)的更多相关文章

  1. PAT 解题报告 1048. Find Coins (25)

    1048. Find Coins (25) Eva loves to collect coins from all over the universe, including some other pl ...

  2. PAT1048:Find Coins

    1048. Find Coins (25) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Eva loves ...

  3. 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 ...

  4. PAT 甲级 1048 Find Coins (25 分)(较简单,开个数组记录一下即可)

    1048 Find Coins (25 分)   Eva loves to collect coins from all over the universe, including some other ...

  5. 1048. Find Coins (25)

    时间限制 50 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Eva loves to collect coins from a ...

  6. PAT1048. Find Coins(01背包问题动态规划解法)

    问题描述: Eva loves to collect coins from all over the universe, including some other planets like Mars. ...

  7. PAT Advanced 1048 Find Coins (25 分)

    Eva loves to collect coins from all over the universe, including some other planets like Mars. One d ...

  8. PAT Advanced 1048 Find Coins (25) [Hash散列]

    题目 Eva loves to collect coins from all over the universe, including some other planets like Mars. On ...

  9. 1048 Find Coins (25分)

    Eva loves to collect coins from all over the universe, including some other planets like Mars. One d ...

随机推荐

  1. 获取MS SQL Server用户存储过程最近修改日期

    最近开发一个网站,已经交给用户测试,不过用户反馈有些问题,需要修改.也许修改的存储过程较多.Insus.NET又懒得做些修改记录,在给用户作更新时,能快速找到最近修改过的存储过程,一一作更新即可. 我 ...

  2. Locust学习总结分享

    简介: Locust是一个用于可扩展的,分布式的,性能测试的,开源的,用Python编写框架/工具,它非常容易使用,也非常好学.它的主要思想就是模拟一群用户将访问你的网站.每个用户的行为由你编写的py ...

  3. 在RobotFramework--RIDE中把日期转化为整型进行运算

    在RobotFramework--RIDE中把日期转化为整型进行运算 运行结果: 20180906 16:10:17.919 : INFO : ${time} = 2018-09-06 16:10:1 ...

  4. ssh 免密码远程登录

    背景: 公司有两台服务器A与B,经常会碰到代码中的配置文件不一致的情况...............,为了反面让两台服务器配置统一,所以需要写个shell脚本,用到的linux命令主要是scp 1.在 ...

  5. CentOS 6.7中安装python3.5

    1.安装一些依赖的软件包 yum groupinstall "Development tools" yum install zlib-devel bzip2-devel opens ...

  6. [python]glob模块中的glob()函数为什么返回空列表??

    最近在学习语音的知识,看一个语音合成实现的相关工具包的源代码,碰到了glob()函数.然后开启了我与这个函数相爱想杀的一个下午. 摘自官网解释: https://docs.python.org/2/l ...

  7. Spring MVC零配置(全注解)(版本5.0.7)

    // 核心配置类 package spittr.config; import org.springframework.web.servlet.support.AbstractAnnotationCon ...

  8. 三大文本处理工具grep、sed及awk

    一.   用grep在文件中搜索文本 grep能够接受正则表达式,生成各种格式的输出.除此之外,它还有大量有趣的选项. 1.  搜索包含特定模式的文本行: 2.  从stdin中读取: 3.  单个g ...

  9. iOS 11 ScrollView偏移问题解决

    if (@available(iOS 11.0, *)){//避免滚动视图顶部出现20的空白以及push或者pop的时候页面有一个上移或者下移的异常动画的问题 [[UIScrollView appea ...

  10. DB2存储过程标准

    CREATE OR REPLACE PROCEDURE "FCT"."PROC_FCT_DSB_SERIES"(IN ACCOUNTING_DATE DATE) ...