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

#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<map>
#include<queue>
#include<string>
#include<vector>
using namespace std; const int maxn=+;
int a[maxn];
int n,k; int main()
{
scanf("%d%d",&n,&k);
for(int i=;i<=n;i++) scanf("%d",&a[i]);
sort(a+,a++n);
int Find=;
for(int i=;i<=n;i++)
{
int l=i+,r=n;
while(l<=r)
{
int mid=(l+r)/;
if(a[mid]>k-a[i]) r=mid-;
else if(a[mid]<k-a[i]) l=mid+;
else {Find=;break;}
}
if(Find==)
{
printf("%d %d\n",a[i],k-a[i]);
break;
}
}
if(Find==) printf("No Solution\n");
return ;
}

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. hdu_5221_Occupation(树剖)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=5221 题意:给你一棵树,每个节点有一定的值,有三种操作: 1 x y 表示占领树上x-y的所有节点,2 ...

  2. hdu 1425 sort

    Problem Description 给你n个整数,请按从大到小的顺序输出其中前m大的数.   Input 每组测试数据有两行,第一行有两个数n,m(0<n,m<1000000),第二行 ...

  3. Django:之传递数据给JS、Ajax和Ajax CSRF认证

    Django传递数据给JS 有时候我们想把一个list或者dict传递给javascript,处理后显示到网页上,比如要用js进行可视化到数据. 请注意:如果是不处理,直接显示在网页上,用Django ...

  4. EntityFramework日志记录

    首先在应用启动时执行:DbInterception.Add(new LogFormatter());   然后加入如下类: #region [ EF的数据库执行日志记录 ] public class ...

  5. c++ lower_bound upper_bound

    lower_bound, first greater than or equal to upper_bound, first strickly greater

  6. Linux 配置VNC远程桌面

    X11 提供的 display manager 为 xdm ,而著名的 KDE 与 GNOME 也都有自己的 display manager 管理程序,分别是 kdm 与 gdm .你可以透过三者中任 ...

  7. perl中调用cgi

    来源: http://www.cnblogs.com/itech/archive/2012/09/23/2698856.html 参考:http://www.willmaster.com/librar ...

  8. ReactiveX--响应式编程の相关概念 浅析

    在许多软件编程任务中,你或多或少期待你的指令将会按照你已经写好的顺序,依次增量执行和完成.但在ReactiveX,很多指令可以通过“观察者”并行执行,其结果将以任意顺序被捕获.你定义了一种“可观察的形 ...

  9. cocos2d-js 帧序列动画

    1.resource.js var res = { playerWalk_plist:"res/playerWalk.plist", playerWalk_png:"re ...

  10. 2016中国大学生程序设计竞赛 - 网络选拔赛 1011 Lweb and String

    Problem Description Lweb has a string S. Oneday, he decided to transform this string to a new sequen ...