CF-395A1 Skis (two pointer)
来源:互联网 发布:mysql 1054错误 编辑:程序博客网 时间:2024/06/05 01:20
先对无序序列排序,一个正方向移动,一个从逆方向移动。时间复杂度竟为O(n)。
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std ;int a[1000005];int main(){int n,q,l,r,ans; while(scanf("%d %d",&n,&q)!=EOF){for(int i=0;i<n;i++) scanf("%d",&a[i]);sort(a,a+n);l=0,r=n-1;ans=0;while(l<r){while(a[l]+a[r]>q&&r>l) r--;if(a[l]+a[r]==q&&(l!=r)){r--;ans++;}l++;}printf("%d\n",ans); } return 0 ;}
0 0
- CF-395A1 Skis (two pointer)
- Two-pointer technique
- [Algorithm]九章七:Two Pointer
- 11572 - Unique Snowflakes(two pointer)
- 掉坑记录--two pointer
- <cf>Two Problems
- 【two-pointer】Codeforces762C[Two strings]题解
- a1
- a1
- a1
- A1
- CF - 223 - B. Two Strings
- CF 251D Two Sets
- The two-dimensional pointer operation in C++
- 11536 - Smallest Sub-Array (two pointer)
- String two pointer swapping (合集)
- LeetCode Minimum Window Substring(two pointer)
- [POJ 2100] Graveyard Design (Two Pointer)
- TAB带地线滑动效果(类似QQ)
- 使用notepad ++快速编译c++程序 !
- BeanFactory与ApplicationContext随记
- 【闲谈】应聘时要问HR的7个问题
- System V 的IPC机制
- CF-395A1 Skis (two pointer)
- 记录一下,从菜鸟做起
- SPI总线协议及SPI时序图详解
- 算法学习(一)
- 什么是java序列化,如何实现java序列化?
- Learning Hadoop (2)
- java 访问fastdfs
- PAT basic 1013 : 被素数
- HDU-2032-杨辉三角