PAT_A1048#Find Coins
Source:
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 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
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的更多相关文章
- [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 ...
- 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 ...
- 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 ...
- csuoj 1119: Collecting Coins
http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1119 1119: Collecting Coins Time Limit: 3 Sec Memo ...
- Coins
Description Whuacmers use coins.They have coins of value A1,A2,A3...An Silverland dollar. One day Hi ...
- hdu 1398 Square Coins (母函数)
Square Coins Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tota ...
- (混合背包 多重背包+完全背包)The Fewest Coins (poj 3260)
http://poj.org/problem?id=3260 Description Farmer John has gone to town to buy some farm supplies. ...
- POJ3260The Fewest Coins[背包]
The Fewest Coins Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 6299 Accepted: 1922 ...
- POJ1742 Coins[多重背包可行性]
Coins Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 34814 Accepted: 11828 Descripti ...
随机推荐
- java对象属性为date oracle数据库字段为Timestamp 处理方式
解决方案 SimpleDateFormat df1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); java.util.Date da ...
- python模块学习之HTMLTestRunner模块生成HTML测试报告
#!/usr/bin/env python #-*- coding:utf-8 -*- from HTMLTestRunner import HTMLTestRunner import time im ...
- webstorm 插件安装
1.打勾的表示已经安装 2.没有安装的插件,可以在plugins搜索,在右边搜索结果里点install,然后重启webstorm 3.这里有常用插件 http://blog.csdn.net/xs20 ...
- camunda用户的一些简单操作
act_id_group:存放组信息act_id_membership:存放用户与组的相关信息act_id_user:存放用户act_id_info:存放用户个人信息act_id_tenant:存放租 ...
- Spring Data JPA one to one 共享主键关联
/** * Created by xiezhiyan on 17-9-13. */@Entitypublic class Token { @Id @Column(name = "store_ ...
- 一步一步学Vue(六)https://www.cnblogs.com/Johnzhang/p/7242640.html
一步一步学Vue(六):https://www.cnblogs.com/Johnzhang/p/7237065.html 路由 一步一步学Vue(七):https://www.cnblogs.com ...
- MySQL锁机制浅析
MySQL使用了3种锁机制 行级锁,开销大,加锁慢,会出现死锁,发生锁冲突的概率最高,并发度也最高 表级锁,开销小,加锁快,不会出现死锁,发生锁冲突的概率最低,并发度最低 页级锁,开销和加锁时间界于表 ...
- linux 虚拟机网卡配置
第一种虚拟机 我们常用的虚拟机vmware虚拟机 今天为了学习ngnix,所以配了两台虚拟机.一个centos7 ,一个redhat. 哇啦哇啦安装,so easy,对吧....我选择的是精简版 ...
- 【Luogu】【关卡2-9】带有技巧的搜索(2017年10月)
任务说明:这里的搜索不仅包含了dfs和bfs,还包括剪枝.记录等技巧以加快速度. [USACO06FEB]数字三角形Backward Digit Su… 滑雪 吃奶酪 靶形数独 P1118 [USAC ...
- 62. File类常用方法
为了怕混淆,先说明一些下面要出现的名词意思:例如:D:\\新建文件夹 (2)\\a.txt 和 D:\\新建文件夹 (2)\\aaaa D:\\新建文件夹 (2) 父路径 a.txt ...