1048. Find Coins (25)

时间限制
50 ms
内存限制
32000 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"iostream"
#include "algorithm"
#include<sstream>
#include "string"
#include "map"
#include "vector"
using namespace std;
#define max 1000

int main()
{
int n,m,num;
bool flag=false;
vector<int> vec;
cin >> n >> m;
vec.resize(max+1,0);
for(int i=0;i<n;i++)
{
cin >> num;
vec[num]++;
}
for(int i=1;i<=m/2;i++)
{
vec[i]--;
vec[m-i]--;
if(vec[i]>=0&&vec[m-i]>=0)
{
cout<<i<<" "<<m-i<<endl;
flag = true;
break;
}

}
if(!flag)

cout<<"No Solution"<<endl;

return 0;
}

浙大pat 1048 题解的更多相关文章

  1. 浙大pat 1035题解

    1035. Password (20) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue To prepare f ...

  2. 浙大pat 1025题解

    1025. PAT Ranking (25) 时间限制 200 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Programmi ...

  3. 浙大pat 1011题解

    With the 2010 FIFA World Cup running, football fans the world over were becoming increasingly excite ...

  4. 浙大PAT 7-06 题解

    #include <stdio.h> #include <iostream> #include <algorithm> #include <math.h> ...

  5. 浙大pat 1012题解

    1012. The Best Rank (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue To eval ...

  6. 浙大 pat 1003 题解

    1003. Emergency (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue As an emerg ...

  7. 浙大 pat 1038 题解

    1038. Recover the Smallest Number (30) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHE ...

  8. 浙大 pat 1047题解

    1047. Student List for Course (25) 时间限制 400 ms 内存限制 64000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Y ...

  9. 浙大pat 1054 题解

    1054. The Dominant Color (20) 时间限制 100 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard Behind the scen ...

随机推荐

  1. 有哪些可以将网页另存图片的chrome插件?功能类似网页截图

    说实话chrome插件哪些,想找出最好最强的还真不容易,各有千秋.今天就概括性介绍下一些网页打印,图片另存为等常见需求的chrome插件.1.Awesome ScreenshotAwesome scr ...

  2. Linux连接xshell找不到IP信息

    虚拟机环境下的Linux连接xshell的网络连接找不到eth0(IP)信息的解决方法   1  输入ifconfig,如果有eth0信息,直接填写eth0上面的IP信息   2 输入ifconfig ...

  3. [MFC美化] SkinSharp使用详解2-SkinH.h函数介绍

    SkinSharp功能强大,该皮肤库支持完全多种颜色改变等. 下面是静态链接库时的SkinH.h头文件: /*在Stdafx.h文件中加入如下语句 #include "SkinH.h&quo ...

  4. CentOS 7上的性能监控工具

    Linux中基于命令行的性能监控工具:dstat.top.netstat.vmstat.htop.ss.glances 1.dstat – 多类型资源统计工具(需配置epel源) 该命令整合了vmst ...

  5. android下拉刷新控件 android-pulltorefresh

    运行效果: 介绍:ListView.ViewPager.WevView.ExpandableListView.GridView.(Horizontal)ScrollView.Fragment上下左右拉 ...

  6. ecstore在MySQL5.7下维护报错WARNING:512 @ ALTER IGNORE TABLE

    ecstore在MySQL5.7下维护报错WARNING:512 @ ALTER IGNORE TABLE 打开 /app/base/lib/application/dbtable.php , 替换A ...

  7. JavaScript基础(更新第二波)

    下面接着说JavaScript打开新的窗口. open()方法可以查找一个已经存在或者新建的浏览器窗口. 语法: window.open([URL]),[窗口名称],[参数字符串] 参数说明: URL ...

  8. 9款.net反编译的必备神器

    编辑来给大家盘点下.net的反编译工具: 1.Reflector Reflector是最为流行的.Net反编译工具.Reflector是由微软员工Lutz Roeder编写的免费程序.Reflecto ...

  9. Thrift学习记录

    Thrift学习记录 Thrift是一个软件框架,用来进行可扩展且跨语言的服务的开发.它结合了功能强大的软件堆栈和代码生成引擎,以构建在C++,Java,Python,PHP,Ruby,Erlang, ...

  10. Python的加入!

    今天有幸领略了Python的风采. 真是好清新>_< 赶紧尝试一下. 好酷. 以后会在项目中使用