先对序列排序,然后枚举较小值,二分较大值。

  1. #include<iostream>
  2. #include<cstring>
  3. #include<cmath>
  4. #include<algorithm>
  5. #include<cstdio>
  6. #include<map>
  7. #include<queue>
  8. #include<string>
  9. #include<vector>
  10. using namespace std;
  11.  
  12. const int maxn=+;
  13. int a[maxn];
  14. int n,k;
  15.  
  16. int main()
  17. {
  18. scanf("%d%d",&n,&k);
  19. for(int i=;i<=n;i++) scanf("%d",&a[i]);
  20. sort(a+,a++n);
  21. int Find=;
  22. for(int i=;i<=n;i++)
  23. {
  24. int l=i+,r=n;
  25. while(l<=r)
  26. {
  27. int mid=(l+r)/;
  28. if(a[mid]>k-a[i]) r=mid-;
  29. else if(a[mid]<k-a[i]) l=mid+;
  30. else {Find=;break;}
  31. }
  32. if(Find==)
  33. {
  34. printf("%d %d\n",a[i],k-a[i]);
  35. break;
  36. }
  37. }
  38. if(Find==) printf("No Solution\n");
  39. return ;
  40. }

PAT (Advanced Level) 1048. Find Coins (25)的更多相关文章

  1. PAT 解题报告 1048. Find Coins (25)

    1048. Find Coins (25) Eva loves to collect coins from all over the universe, including some other pl ...

  2. PTA(Advanced Level)1048.Find Coins

    Eva loves to collect coins from all over the universe, including some other planets like Mars. One d ...

  3. PAT (Advanced Level) 1114. Family Property (25)

    简单DFS. #include<cstdio> #include<cstring> #include<cmath> #include<vector> # ...

  4. PAT (Advanced Level) 1109. Group Photo (25)

    简单模拟. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #i ...

  5. PAT (Advanced Level) 1105. Spiral Matrix (25)

    简单模拟. #include<cstdio> #include<cstring> #include<cmath> #include<map> #incl ...

  6. PAT (Advanced Level) 1101. Quick Sort (25)

    树状数组+离散化 #include<cstdio> #include<cstring> #include<cmath> #include<map> #i ...

  7. PAT (Advanced Level) 1071. Speech Patterns (25)

    简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...

  8. PAT (Advanced Level) 1063. Set Similarity (25)

    读入之后先排序. 询问的时候可以o(m)效率得到答案. #include<cstdio> #include<cstring> #include<cmath> #in ...

  9. PAT (Advanced Level) 1059. Prime Factors (25)

    素因子分解. #include<iostream> #include<cstring> #include<cmath> #include<algorithm& ...

随机推荐

  1. INI文件的写入与读取

    INI文件的写入与读取 [节名]         '[]中的节名对应此API的第一参数 Name=内容      'Nmae对应此API的第二参数 API的第三参数是没有取到匹配内容时返回的字符串; ...

  2. Codeforces Round #350 (Div. 2)_D2 - Magic Powder - 2

    D2. Magic Powder - 2 time limit per test 1 second memory limit per test 256 megabytes input standard ...

  3. python--lambda和def函数

    1.Python lambda和Python def区别分析 Python支持一种有趣的语法,它允许你快速定义单行的最小函数.这些叫做lambda的函数,是从Lisp借用来的,可以用在任何需要函数的地 ...

  4. jsp第1讲(上集)

    jsp讲解框架 (一)Java EE核心十三种技术介绍 (二)Java EE程序员修炼成精的法门 (三)jsp版本的用户管理系统演示 (四)jsp概述 (五)jsp的运行原理 (六)jsp版的计算器 ...

  5. how to write a struct to a file directly?

    Using write and read system call. Following is an example: blk.h: #include <stdlib.h> #include ...

  6. spring 基于XML和注解的两种事务配置方式

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  7. go share library

    http://blog.ralch.com/tutorial/golang-sharing-libraries/ Sharing Golang packages to C and Go Sun, Au ...

  8. asp发邮件控件

    <% Set jmail = Server.CreateObject("JMAIL.SMTPMail") ’创建一个JMAIL对象 jmail.silent = true ’ ...

  9. oracle登陆,在监听服务启动了的情况下,登陆用户还是报错未启动监听服务的错误(刚开始装oracle是能登陆的,重启之后装了plsql)

    刚开始装oracle是能登陆的,重启之后装了140M的plsql,所以有可能是plsql跟oracle监听冲突了,所以我之后换了33M的plsql,oracle就没问题了,可以正常登陆了

  10. List<string[]> 如何去重

    List<string[]> 如何去重,代码如下: static void Main(string[] args) { List<string[]> list = new Li ...