PAT (Advanced Level) 1048. Find Coins (25)
先对序列排序,然后枚举较小值,二分较大值。
- #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)的更多相关文章
- PAT 解题报告 1048. Find Coins (25)
1048. Find Coins (25) Eva loves to collect coins from all over the universe, including some other pl ...
- PTA(Advanced Level)1048.Find Coins
Eva loves to collect coins from all over the universe, including some other planets like Mars. One d ...
- PAT (Advanced Level) 1114. Family Property (25)
简单DFS. #include<cstdio> #include<cstring> #include<cmath> #include<vector> # ...
- PAT (Advanced Level) 1109. Group Photo (25)
简单模拟. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #i ...
- PAT (Advanced Level) 1105. Spiral Matrix (25)
简单模拟. #include<cstdio> #include<cstring> #include<cmath> #include<map> #incl ...
- PAT (Advanced Level) 1101. Quick Sort (25)
树状数组+离散化 #include<cstdio> #include<cstring> #include<cmath> #include<map> #i ...
- PAT (Advanced Level) 1071. Speech Patterns (25)
简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...
- PAT (Advanced Level) 1063. Set Similarity (25)
读入之后先排序. 询问的时候可以o(m)效率得到答案. #include<cstdio> #include<cstring> #include<cmath> #in ...
- PAT (Advanced Level) 1059. Prime Factors (25)
素因子分解. #include<iostream> #include<cstring> #include<cmath> #include<algorithm& ...
随机推荐
- INI文件的写入与读取
INI文件的写入与读取 [节名] '[]中的节名对应此API的第一参数 Name=内容 'Nmae对应此API的第二参数 API的第三参数是没有取到匹配内容时返回的字符串; ...
- 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 ...
- python--lambda和def函数
1.Python lambda和Python def区别分析 Python支持一种有趣的语法,它允许你快速定义单行的最小函数.这些叫做lambda的函数,是从Lisp借用来的,可以用在任何需要函数的地 ...
- jsp第1讲(上集)
jsp讲解框架 (一)Java EE核心十三种技术介绍 (二)Java EE程序员修炼成精的法门 (三)jsp版本的用户管理系统演示 (四)jsp概述 (五)jsp的运行原理 (六)jsp版的计算器 ...
- 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 ...
- spring 基于XML和注解的两种事务配置方式
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...
- go share library
http://blog.ralch.com/tutorial/golang-sharing-libraries/ Sharing Golang packages to C and Go Sun, Au ...
- asp发邮件控件
<% Set jmail = Server.CreateObject("JMAIL.SMTPMail") ’创建一个JMAIL对象 jmail.silent = true ’ ...
- oracle登陆,在监听服务启动了的情况下,登陆用户还是报错未启动监听服务的错误(刚开始装oracle是能登陆的,重启之后装了plsql)
刚开始装oracle是能登陆的,重启之后装了140M的plsql,所以有可能是plsql跟oracle监听冲突了,所以我之后换了33M的plsql,oracle就没问题了,可以正常登陆了
- List<string[]> 如何去重
List<string[]> 如何去重,代码如下: static void Main(string[] args) { List<string[]> list = new Li ...