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. Leetcode-37-Sudoku Solver(Hard)

    此处先留空 使用搜索和回溯,递归来实现 参考:http://blog.csdn.net/zxzxy1988/article/details/8586289 描述简介,代码量最少

  2. delphi 程序输出文件夹存放位置

  3. Linux的一些简单命令(三)

    1.解压缩算法:使用gzip算法进行解压缩,   压缩语法:gzip filename   解压语法:gzip -dv filename 2.解压缩算法:使用bzip2算法进行解压缩, 压缩语法:bz ...

  4. Winform DataGridView直接导出Excel

    /// <summary> /// 导出excel /// </summary> /// <param name="fileName">导出文件 ...

  5. 在VMware上安装CentOS -7步骤详解

    在VMware上安装CentOS -7 一.下载好VMware虚拟机 二.准备好CentOS的镜像文件 在这里安装之前博主都已准备好了. 废话就少啰嗦啦!现在开始安装步骤了 1.首先打开VMware创 ...

  6. 使用 Jenkins 搭建 iOS/Android 持续集成打包平台【转】

    背景描述 根据项目需求,现要在团队内部搭建一个统一的打包平台,实现对iOS和Android项目的打包.而且为了方便团队内部的测试包分发,希望在打包完成后能生成一个二维码,体验用户(产品.运营.测试等人 ...

  7. ssh框架的小实例(用户登录)

    刚学SSH框架写一个小实例,以便以后查看: 本案例简单的实现一个用户登录: 数据库方面就不写了,自己领悟吧!哈哈(根据user.hbm.xml文件就知道了) 我们一般可以创建下面几个包,什么意思呢,自 ...

  8. Web中的无状态含义

    REST架构设计是目前非常火热的概念,已经成为构建web服务时应该遵循的事实标准.REST约束中有一条很重要的规则是“无状态”,但“无状态”是个很抽象的概念,对刚刚接触的人来讲,很难深刻形象的理解.今 ...

  9. onkeyup事件只能输入数字,字母,下划线

    <input type="text" onkeyup="value=value.replace(/[\W]/g,'')"/>

  10. Struts2 注解零配置方法(convention插件使用)

    最近接触到一个新的项目,是做一个使用S2SH的电子商务商城的二次开发.之前使用过S2SH,在此之前的项目中,Struts2 使用的是XML配置而这个项目是使用注解.在这个项目中,注解还不需要使用Act ...