Source:

PAT A1048 Find Coins (25 分)

Description:

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 1 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 (≤, the total number of coins) and M (≤, 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 V​1​​ and V​2​​ (separated by a space) such that V​1​​+V​2​​=M and V​1​​≤V​2​​. If such a solution is not unique, output the one with the smallest V​1​​. 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

Keys:

Attention:

  • 所给数字超过了500

Code:

 /*
Data: 2019-07-21 20:01:45
Problem: PAT_A1048#Find Coins
AC: 11:22 题目大意:
给定整数s,从数集中找出a+b=s
*/ #include<cstdio>
const int M=1e3;
int mp[M]={}; int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("Test.txt", "r", stdin);
#endif int n,s,t;
scanf("%d%d", &n,&s);
for(int i=; i<n; i++)
{
scanf("%d", &t);
mp[t]++;
}
for(int i=; i<=s/; i++)
{
if(mp[i] && mp[s-i] && i!=s-i)
{
printf("%d %d", i,s-i);
s=;break;
}
}
if(s!= && s%== && mp[s/]>)
printf("%d %d", s/,s/);
else if(s!=)
printf("No Solution"); return ;
}

PAT_A1048#Find Coins的更多相关文章

  1. [LeetCode] Arranging Coins 排列硬币

    You have a total of n coins that you want to form in a staircase shape, where every k-th row must ha ...

  2. ACM: Gym 101047M Removing coins in Kem Kadrãn - 暴力

     Gym 101047M Removing coins in Kem Kadrãn Time Limit:2000MS     Memory Limit:65536KB     64bit IO Fo ...

  3. Codeforces 2016 ACM Amman Collegiate Programming Contest A. Coins(动态规划/01背包变形)

    传送门 Description Hasan and Bahosain want to buy a new video game, they want to share the expenses. Ha ...

  4. csuoj 1119: Collecting Coins

    http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1119 1119: Collecting Coins Time Limit: 3 Sec  Memo ...

  5. Coins

    Description Whuacmers use coins.They have coins of value A1,A2,A3...An Silverland dollar. One day Hi ...

  6. hdu 1398 Square Coins (母函数)

    Square Coins Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tota ...

  7. (混合背包 多重背包+完全背包)The Fewest Coins (poj 3260)

    http://poj.org/problem?id=3260   Description Farmer John has gone to town to buy some farm supplies. ...

  8. POJ3260The Fewest Coins[背包]

    The Fewest Coins Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6299   Accepted: 1922 ...

  9. POJ1742 Coins[多重背包可行性]

    Coins Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 34814   Accepted: 11828 Descripti ...

随机推荐

  1. thinkphp5 图片上传七牛云

    <?php namespace app\cxc\controller; use Qiniu\Auth; use Qiniu\Storage\UploadManager; use think\Co ...

  2. Hive 时间操作函数(转)

    1.日期函数UNIX时间戳转日期函数: from_unixtime 语法:   from_unixtime(bigint unixtime[, string format]) 返回值: string ...

  3. 简单gui

    import java.awt.Button; import java.awt.Frame; import java.awt.event.WindowAdapter; import java.awt. ...

  4. C++构造函数异常(二)

    继续上一篇文章提到的构造异常话题,下面继续谈另外两个场景,即多继承构造异常,以及智能指针构造异常 第3:对多继承当中,某个基类构造异常,而其他基类已构造成功,则构造成功的基类不会析构,由编译器负责回收 ...

  5. JS检查断网

    window.addEventListener('load', function() { function updateOnlineStatus(event) { var condition = na ...

  6. Mysql 生成随机数字

    其实思路很简单,利用MySQL现有的函数,然后进行加工处理,达到预期的结果.可以用到的MySQL函数为rand() ,以及 round() 函数. 具体为:select round(rand()*10 ...

  7. linux Cron 定时任务(centos 7.2 测试可用)

    1.Cron(学习笔记) 计划任务,是任务在约定的时间执行已经计划好的工作. 格式如下 Seconds Minutes Hours DayofMonth Month DayofWeek Year    ...

  8. SQL必知必会——思维导图

    Xmind实在太坑了,竟然不能导出高清图片,我回来折腾个PS整一下!

  9. 在同一个项目中灵活运用application/json 和application/x-www-form-urlencoded 两种传输格式(配合axios,同时配置loading)

    'use strict' import axios from 'axios' // import qs from 'qs' import { Notification} from 'element-u ...

  10. java漏洞历史

    内容来自以前收集的思维导图,作者不明. 1.JDK漏洞 1.1.CVE-2012-4681 https://www.freebuf.com/vuls/5485.html msf: exploit/mu ...