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. appium自动化测试- 元素操作

    本文转自:https://www.cnblogs.com/sinder2018/articles/9699801.html 一.滑动屏幕 1.appium - 滑动屏幕 滑动接口: swipe(起始X ...

  2. 自动化测试之CSS定位

    之前做自动化测试一直用RF框架来操作,发现了明显与unittest的灵活性相差一点. 重新温习了unittest框架,其中这个框架,元素定位是难点,以前更多的使用JQUERY方式定位, 发现其实与CS ...

  3. 屏蔽浏览器默认样式 user agent stylesheet

    user agent stylesheet <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" &q ...

  4. Oracle中使用REGEXP_SUBSTR,regexp_replace,wm_concat函数

    REGEXP_SUBSTR函数格式如下: function REGEXP_SUBSTR(String, pattern, position, occurrence, modifier)__srcstr ...

  5. 2019牛客多校第六场J-Upgrading Technology(枚举+单调队列)

    Upgrading Technology 题目传送门 解题思路 对于这题,我们可以枚举一个k从0~m,表示当前我们把所有技能最少升到了k级,且至少有一个为k级. 此时我们刚好获得了前k个d[]的收益, ...

  6. org-mode记录总结

    org-mode记录总结 */--> code {color: #FF0000} pre.src {background-color: #002b36; color: #839496;} cod ...

  7. CF1158C

    题意:有排列p, 令\(nxt_i\)为\(p_i\)右侧第一个大于\(p_i\)的数的位置,若不存在则\(nxt_i=n+1\) 现在整个p和nxt的一部分丢失了,请根据剩余的nxt,构造出一个符合 ...

  8. ARC080E

    倒着考虑 每次拿出的第一个必须是奇数位置,第二个必须是偶数位置.每次删数都不能跨过已被删去的位置. 事实上只要开个堆维护一下区间就行了.但是众所周知我zz,所以我写的线段树 #include<i ...

  9. Vs 中的智能提示,默认选中,切换快捷键

    切换是否默认选中,快捷键: Ctrl+Alt+Space(空格)

  10. tac - 反转显示文件

    总览 (SYNOPSIS) ../src/tac [OPTION]... [FILE]... 描述 (DESCRIPTION) 把 每个 文件 FILE 显示在 标准输出, 后面 的 行 放在 前面. ...