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

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

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

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

  4. PAT Advanced 1048 Find Coins (25 分)

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

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

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

  6. 1048 Find Coins (25分)

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

  7. PAT (Advanced Level) 1048. Find Coins (25)

    先对序列排序,然后枚举较小值,二分较大值. #include<iostream> #include<cstring> #include<cmath> #includ ...

  8. PAT甲题题解-1048. Find Coins (25)-水

    给n,m以及n个硬币 问,是否存在两个硬币面值v1+v2=m 因为面值不会超过500,所以实际上最多500个不同的硬币而已 #include <iostream> #include < ...

  9. 【PAT甲级】1048 Find Coins (25 分)(二分)

    题意: 输入两个正整数N和M(N<=10000,M<=1000),然后输入N个正整数(<=500),输出两个数字和恰好等于M的两个数(小的数字尽可能小且输出在前),如果没有输出&qu ...

随机推荐

  1. Android studio设置参数提示

    在Android studio的使用的过程中,那么就需要对当前的代码显示当前的方式做一个的提示信息,那么可以通过Android studio的的设置的方法,来对Android studio方法的提示显 ...

  2. iOS 数据类型

    标签: 数据类型 1.Objective-C数据类型可以分为:基本数据类型.对象数据类型和id类型. 2.基本数据类型有:int.float.double和char类型. 3.对象类型就是类或协议所声 ...

  3. 对于android触摸事件模型的一些理解

    body{ font-family: "Microsoft YaHei UI","Microsoft YaHei",SimSun,"Segoe UI& ...

  4. [改善Java代码]边界,边界,还是边界

    建议24:边界,边界,还是边界 import java.util.Scanner; public class Client { //一个会员拥有产品的最大数量 public final static ...

  5. [未完成]关于Eclipse4RCP书中内容总结

    原文地址http://www.vogella.com/tutorials/EclipseRCP/article.html Table of Contents 1. Eclipse 4 1.1. Wha ...

  6. 关于使用vss版本管理工具中的sln,suo文件作用

    Visual Studio.NET采用两种文件类型(.sln和.suo)来存储特定于解决方案的设置,它们总称为解决方案文件.为解决方案资源管理器提供显示管理文件的图形接口所需的信息 从而在每次继续开发 ...

  7. C# 实现远程控制软件的关键技术

    一.服务器端多线程Socket技术    用TcpListener进行侦听,接受客户端连接,有客户端连进来后开启处理线程处理数据,代码如下:    using System; using System ...

  8. 关于css雪碧图sprite

    天气转凉了,又开始贪恋暖暖的被窝了. 早上不想起床的时候在被窝里看了有关于雪碧图的视频. 1.使用场景 V导航条,登录框img标签多次载入,性能低 X大图banner按需加载,如果做成雪碧图一次加载就 ...

  9. asp.net中web.config配置节点大全详解【转】

    web.config 文件查找规则: (1)如果在当前页面所在目录下存在web.config文件,查看是否存在所要查找的结点名称,如果存在返回结果并停止查找. (2)如果当前页面所在目录下不存在web ...

  10. UML学习-总体概念篇

    前言:我们在实施一个项目时,前期的设计是非常重要的,如建筑师在建造一个建筑时,需要事先设计图纸,设计图纸是设计的语言,是不同的工程设计人员.设计人员和生产人员之间进行沟通的语言,在一个现代化的工程里面 ...