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

#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. 嵌套表SHAPE

    SQL语法 SHAPE {<master query>} APPEND ({ <child table query> } RELATE <master column> ...

  2. spring Stack Overflow

    1. ApplicationContext 不关闭,资源泄露问题: Spring ApplicationContext - Resource leak: 'context' is never clos ...

  3. Java编译成功,用java 运行class时出现错误解决方法

    java -classpath class file's address; filename

  4. Java程序输出打字

    代码: 效果:

  5. html css相对单位

    p{ background:grey; color:white; font-size:0.5in; height:2em; width:50%; } height:2em意思就是屏幕上显示的的高度为字 ...

  6. C#中的Virtual、Override和new关键词理解

    来源:http://blog.csdn.net/jackiezhw/article/details/2673992 在 C# 中,派生类可以包含与基类方法同名的方法. 基类方法必须定义为 virtua ...

  7. THE ROAD TO PROGRAM

    <The C Programming Language> <The Practice of Programming><The Art of Computer Progra ...

  8. bios自检时间长,显示0075错误

    一amibios主板,只有一IDE接口,接一硬盘一光驱,每次启动时,在bios自检界面,在检测完usb设备后,都要等个那么一两分钟,这个时候,可以在屏幕的右下角看到有数字:0075 ,这就是错误代码. ...

  9. dump文件生成与调试(VS2008)

    总结一下dump文件生成和调试的方法: 1:用SetUnhandledExceptionFilter捕获未处理的异常,包含头文件<windows.h>.函数原型为: LPTOP_LEVEL ...

  10. Windows下将ImageMagick移植到Android平台

    Windows下将ImageMagick移植到Android平台 原文链接  http://www.pedant.cn/2014/06/18/imagemagick-ported-android/ I ...