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. react-gulp-browserify

    环境搭配参照 http://www.cnblogs.com/guolaomao/p/6276877.html 前半部分的内容. 首先安装browserify npm install --save-de ...

  2. SDN理解:云数据中心底层网络架构

    目录 - 目录 - 云数据中心流量类型 - NSX整体网络结构 - 管理网络(API网络) - 租户网络 - 外联网络 - 存储网络 - openstack整体网络结构 - 管理网络:(上图中蓝线) ...

  3. 快速掌握LODOP打印使用方法

    用运之前简单介绍几个东西. install_lodop32.exe与install_lodop64.exe这两个是2个网页打印控件,网页打印必须安装这个控件在客户端,分为32和64位安装控件.(如果自 ...

  4. Web网页数据抓取(C/S)

    通过程序自动的读取其它网站网页显示的信息,类似于爬虫程序.比方说我们有一个系统,要提取BaiDu网站上歌曲搜索排名.分析系统在根据得到的数据进行数据分析.为业务提供参考数据. 为了完成以上的需求,我们 ...

  5. HTML5扩展之微数据与丰富网页摘要itemscope, itemtype, itemprop

    HTML5扩展之微数据与丰富网页摘要 by zhangxinxu from http://www.zhangxinxu.com本文地址:http://www.zhangxinxu.com/wordpr ...

  6. EasyUI Messager 消息框

    通过 $.messager.defaults 重写默认的 defaults. 消息框(messager)提供不同样式的消息框,包括警示(alert).确认(confirm).提示(prompt).进展 ...

  7. Spring Security(18)——Jsp标签

    目录 1.1     authorize 1.2     authentication 1.3     accesscontrollist Spring Security也有对Jsp标签的支持的标签库 ...

  8. linux for 使用

    第一种:命令使用方法 例子1: cat test.txt 1 2 3 for i in $(cat test.txt) do echo $i done 例子2: for i in 1 2 3 4 do ...

  9. python字符串及正则表达式[转]

    原文链接:http://www.cnblogs.com/guojidong/archive/2012/12/20/2826388.html 字符串: 正则表达式 正则表达式元字符与语法图: 注意事项: ...

  10. ELK 日志系统搭建配置

    logstash是一个数据分析软件,主要目的是分析log日志.整一套软件可以当作一个MVC模型,logstash是controller层,Elasticsearch是一个model层,kibana是v ...