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 ...
随机推荐
- easyui rowspan
第一种写法 columns: [ [ { field: 'depName', title: '部门', rowspan: 2, width: '100px', align: 'center' }, { ...
- TigerVNC编译安装
TigerVNC official site:http://www.linuxfromscratch.org/blfs/view/svn/xsoft/tigervnc.html TigerVNC版本: ...
- Django会话,用户和注册之用户认证
通过session,我们可以在多次浏览器请求中保持数据, 接下来的部分就是用session来处理用户登录了. 当然,不能仅凭用户的一面之词,我们就相信,所以我们需要认证. 当然了,Django 也提供 ...
- 【转】ROWNUM与ORDER BY先后关系
源地址:http://www.cnblogs.com/accumulater/p/6137385.html
- 基本css拼图形
关闭按钮: <em class="close"></em> .close { width: 16px; height: 16px; text-align: ...
- linux select代码框架
#define PORT 1234 #define BACKLOG 5 #define MAXDATASIZE 1000 typedef struct CLIENT{ int fd; char* na ...
- SprimgMVC学习笔记(四)—— @RequestMapping
一.URL路径映射 @RequestMapping(value="item")或@RequestMapping("/item") 当value的值是数组时,可以 ...
- AngularJS页面【uib-dropdown】控件在模态窗口(弹出窗)中无法使用问题
如果你的下拉框中有属性 dropdown-append-to-body 将它去掉,即可正常使用该插件. <div class="btn-group dropdown" uib ...
- 江西财经大学第一届程序设计竞赛 F
链接:https://www.nowcoder.com/acm/contest/115/F来源:牛客网 题目描述 对于方程 2018 * x ^ 4 + 21 * x + 5 * x ^ 3 + 5 ...
- AD域账号验证
public partial class _Default : Page { [DllImport("advapi32.dll")] private static extern b ...