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 <stdio.h>
int main()
{
int n,line,i;
int hash[];
while(scanf("%d%d",&n,&line)!=EOF)
{
getchar();
for(i = ;i<=;i++)
hash[i] = ;
for(i = ;i<n;i++)
{
int tem;
scanf("%d",&tem);
++hash[tem];
} bool find = false;
for(i = ;i<= line/;++i)
{
if(hash[i]>)
{
--hash[i];
if(hash[line-i]>)
{
find = true;
break;
}
else
{
++hash[i];
}
}
} if(find)
{
printf("%d %d\n",i,line-i);
}
else
{
printf("No Solution\n");
} }
return ;
}
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 pl ...
- 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 ...
- 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 ...
- PAT (Advanced Level) 1048. Find Coins (25)
先对序列排序,然后枚举较小值,二分较大值. #include<iostream> #include<cstring> #include<cmath> #includ ...
- PAT甲题题解-1048. Find Coins (25)-水
给n,m以及n个硬币 问,是否存在两个硬币面值v1+v2=m 因为面值不会超过500,所以实际上最多500个不同的硬币而已 #include <iostream> #include < ...
- 【PAT甲级】1048 Find Coins (25 分)(二分)
题意: 输入两个正整数N和M(N<=10000,M<=1000),然后输入N个正整数(<=500),输出两个数字和恰好等于M的两个数(小的数字尽可能小且输出在前),如果没有输出&qu ...
随机推荐
- Redis' High Availability
Redis Sentinel is a system designed to help managing Redis instances. It performs the following thre ...
- Linux 通过 load average 判断服务器负载情况
Linux中load average判断服务器负载情况 转载文章 http://www.111cn.net/sys/linux/56003.htm 写的比较详细,推荐看看.
- linux压缩解压缩
一.tar • -c:创建新文档• -x:解压缩归档文件• -f 文件名:使用归档文件• -j:使用bzip2解压缩• -z:使用gzip解压缩• -v:详细输出模式 1.压缩命令: 命令格式:tar ...
- .net平台 .net Framework 组织结构 .net Framework类库 CLR C# 介绍
一..net平台 .NET现在可以看成微软的一个品牌,微软有两个非常成功的品牌,那就是Windows和Office. .NET会成为微软的另一个品牌.它不仅仅是一组技术,产品,或服务(微软的服务包括M ...
- markdown编辑
有用的技巧之,如何实现首行空两格,把输入法切换成全角(shift+space),就可以实现一个两字符的空格了. 一级标题 二级标题 三级标题 四级标题 五级标题 六级标题 w s r s r s 文本 ...
- SQL自动补充其他月份为0
,) ), Sales int,Dates datetime) insert into ProductSale ,'2014-01-05' UNION ALL ,'2014-02-05' UNION ...
- PHP学习笔记 - 进阶篇(4)
PHP学习笔记 - 进阶篇(4) 字符串操作 字符串介绍 PHP开发中,我们遇到最多的可能就是字符串. 字符串变量用于包含字符串的值. 一个字符串 通过下面的3种方法来定义: 1.单引号 2.双引号 ...
- C# 数据结构--单链表
什么是单链表 这两天看到很多有关单链表的面试题,对单链表都不知道是啥的我.经过学习和整理来分享一下啥是单链表和单链表的一些基本使用方法.最后看些网上有关单链表的面试题代码实例. 啥是单链表? 单链表是 ...
- 设置 MyEclipse 默认打开文件方式
在web开发时,我们在打开JSP页面时,MyEclipse默认使用 Vistual 的方式打开.这种方式打开JSP页面时,很慢.在实际的开发过程中我们不想使用这种默认的方式打开JSP.设置如 ...
- PHP的语言规范
PHP的语言规范: 1.php中的变量名区分大小写,但是函数名,类名,方法名,不区分大小写,但建议区分大小写 2.php代码必须书写在<?php?>(php标签),开启标记(<?ph ...