PAT甲 1048. Find Coins (25) 2016-09-09 23:15 29人阅读 评论(0) 收藏
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 105coins 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<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
int cnt[5005];
int main()
{
int i,j,temp;
int n,m;
scanf("%d%d",&n,&m);
for (i=0;i<n;i++)
{
scanf("%d",&temp);
cnt[temp]++;
}
for (i=1;i<=m-i;i++)
{
cnt[i]--;cnt[m-i]--;
if (cnt[i]>=0&&cnt[m-i]>=0)
break;
}
if (i<=m-i)
printf("%d %d\n",i,m-i);
else
printf("No Solution\n");
return 0;
}
PAT甲 1048. Find Coins (25) 2016-09-09 23:15 29人阅读 评论(0) 收藏的更多相关文章
- PAT甲 1032. Sharing (25) 2016-09-09 23:13 27人阅读 评论(0) 收藏
1032. Sharing (25) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue To store Engl ...
- PAT甲 1029. Median (25) 2016-09-09 23:11 27人阅读 评论(0) 收藏
1029. Median (25) 时间限制 1000 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given an incr ...
- PAT甲 1009. Product of Polynomials (25) 2016-09-09 23:02 96人阅读 评论(0) 收藏
1009. Product of Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...
- PAT甲 1046. Shortest Distance (20) 2016-09-09 23:17 22人阅读 评论(0) 收藏
1046. Shortest Distance (20) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The ...
- PAT甲 1041. Be Unique (20) 2016-09-09 23:14 33人阅读 评论(0) 收藏
1041. Be Unique (20) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Being uniqu ...
- PAT甲 1011. World Cup Betting (20) 2016-09-09 23:06 18人阅读 评论(0) 收藏
1011. World Cup Betting (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Wit ...
- PAT甲 1008. Elevator (20) 2016-09-09 23:00 22人阅读 评论(0) 收藏
1008. Elevator (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The highest ...
- 本周博客--WinForm线程初步 2014-10-31 09:15 54人阅读 评论(0) 收藏
嗯,WinForm作为一个比较程序的微软的技术已经为我们服务了很久很久,在技术不断更新的今天WinForm虽显老态龙钟但是在客户端快速开发中,它的地位还是无可取代的 今天就来分享一下WinForm中的 ...
- PIGS 分类: POJ 图论 2015-08-10 09:15 3人阅读 评论(0) 收藏
PIGS Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 18209 Accepted: 8277 Description Mir ...
随机推荐
- JQUERY伸缩导航
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- window 下复制 cmd内容
https://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/windows_dos_copy.msp ...
- 利用R产生随机数
生成随机数有两个函数runif()和rnorm(),其中r表示的是random随机的意思,unif表示的是均匀分布,而norm表示的是正态分布. 1)生成10个2到3之间的,服从均匀分布的随机数:ru ...
- hibernate经常报的几个不起眼的错误, 都是因为不细心或者手滑了输入有误造成了
最近会经常用到hibernate了, 也经常报错, 看着屏幕上一根大红条是非常不爽的, 这几天集合了一下经常报的错误, 整合一下放到这里, 以后再出现这个错误直接去解决就好了 1, org.hiber ...
- configparser模块 logging模块
configparser模块 固定格式的配置文件 有一个对应的模块去帮你做这个文件的字符串处理 config = configparser.Configparser() config.read(“ex ...
- 【JVM】浅谈双亲委派和破坏双亲委派
一.前言 笔者曾经阅读过周志明的<深入理解Java虚拟机>这本书,阅读完后自以为对jvm有了一定的了解,然而当真正碰到问题的时候,才发现自己读的有多粗糙,也体会到只有实践才能加深理解,正应 ...
- 读书笔记---改善c#编程的157个建议
1.在拼接string时,如果牵涉到其他类型,先tostring一下会减少装箱操作:频繁操作字符串变量的话,使用stringbuilder效率较高. 2.tryParse相对于parse而言效率高,t ...
- Codeforces 595B. Pasha and Phone 容斥
B. Pasha and Phone time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- Linux 磁盘分区存放文件和目录的数量 (inode)
文件系统格式centos7缺省是xfs,centos6缺省是ext4,centos5缺省是ext3ext3 文件数最大支持31998个,文件系统容量最大16TB,单个文件最大2TBext4 文件数最大 ...
- 不能错过的Sketch实用新技巧和资源集锦
Sketch是一款基于Mac的矢量绘图应用.面对着功能复杂繁琐的photoshop,Sketch相比较而言身轻如燕.最近也掀起了用Sketch设计产品原型的热潮,因为用它来画设计稿简直轻而易举,相比于 ...