1048 Find Coins
题意:略
思路:two pointers思想,简单
先对数字序列进行排序,然后定义两个指针left和right,初始状态low=0,high=n-1。当a[low]+a[high] > M时,high向左移动;当a[low]+a[high] < M时,left向右移动。
代码:
#include <cstdio>
#include <algorithm>
using namespace std;
;
int value[N];
int main()
{
int n,m;
scanf("%d%d",&n,&m);
;i<n;i++)
scanf("%d",&value[i]);
sort(value,value+n);
,high=n-;
while(low<high){
if(value[low]+value[high]==m) break;
else if(value[low]+value[high]>m) high--;
else low++;
}
if(low==high) printf("No Solution\n");
else printf("%d %d\n",value[low],value[high]);
;
}
1048 Find Coins的更多相关文章
- PAT 解题报告 1048. Find Coins (25)
1048. Find Coins (25) Eva loves to collect coins from all over the universe, including some other pl ...
- 1048 Find Coins (25 分)
1048 Find Coins (25 分) Eva loves to collect coins from all over the universe, including some other p ...
- PAT甲 1048. Find Coins (25) 2016-09-09 23:15 29人阅读 评论(0) 收藏
1048. Find Coins (25) 时间限制 50 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Eva loves t ...
- PAT 1048 Find Coins[比较]
1048 Find Coins (25 分) Eva loves to collect coins from all over the universe, including some other p ...
- PAT 甲级 1048 Find Coins (25 分)(较简单,开个数组记录一下即可)
1048 Find Coins (25 分) Eva loves to collect coins from all over the universe, including some other ...
- 1048. Find Coins (25)
时间限制 50 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Eva loves to collect coins from a ...
- PAT 1048. Find Coins
two sum题目,算是贪婪吧 #include <cstdio> #include <cstdlib> #include <vector> #include &l ...
- PAT 甲级 1048 Find Coins
https://pintia.cn/problem-sets/994805342720868352/problems/994805432256675840 Eva loves to collect c ...
- 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 1048 Find Coins (25 分)
Eva loves to collect coins from all over the universe, including some other planets like Mars. One d ...
随机推荐
- Linux 任务控制(bg job fg nohup &) (转)
常用命令 & 将指令丢到后台中去执行[ctrl]+z 將前台任务丟到后台中暂停jobs 查看后台的工作状态fg %jobnumber 将后台的任务拿到前台来处理bg %jobnumber 将任 ...
- 关于绑定的C#代码+转换器
BindingOperations.SetBinding( exp, Expander.IsExpandedProperty, new Bi ...
- MSSQL2008 临时总结文档2014
2. 索引可以建立在基表上(基表索引),也可以视图上称为视图索引. 基表索引是建立在表数据中的,故视图索引是建立在查询后的结果集上的. (假如建立了视图索引)当从视图中取数据的时候,优化查询分析器会 ...
- MVC,MVP 和 MVVM 的图示,区别
作者: 阮一峰 日期: 2015年2月 1日 复杂的软件必须有清晰合理的架构,否则无法开发和维护. MVC(Model-View-Controller)是最常见的软件架构之一,业界有着广泛应用.它本身 ...
- 各种WEB服务器自带的默认Servlet名称
Tomcat, Jetty, JBoss, and GlassFish 自带的默认Servlet的名字 -- "default" Google App Engine 自带的 默认S ...
- 18-THREE.JS 基本材质
<!DOCTYPE html> <html> <head> <title></title> <script src="htt ...
- LeetCode OJ:Remove Duplicates from Sorted Array II(移除数组中的重复元素II)
Follow up for "Remove Duplicates":What if duplicates are allowed at most twice? For exampl ...
- 谈一下思考,关于mybatis中<foreach collection="list">中list得来的原因 没看到官方说明
<foreach> 是在sql语句中进行多个id查询 时用到的,因为mybatis代替jdbc和hibernate, 使用 在xml文件中编写sql语句,这是一个标签文件.然后在 dao层 ...
- Qt之格栅布局(QGridLayout)
简述 QGridLayout:格栅布局,也被称作网格布局(多行多列). 栅格布局将位于其中的窗口部件放入一个网状的栅格之中.QGridLayout需要将提供给它的空间划分成的行和列,并把每个窗口部件插 ...
- MySQL 5.7.18 在centos下安装记录
一个朋友找我如何在linux下安装mysql5.7.18,我稍微整理下了下记录,如下: 下载地址: MySQL5.7.18参数官方网址:https://dev.mysql.com/doc/refman ...