这题没名字

Problem:I

Time Limit:2000ms

Memory Limit:65535K

Description

Now give you an interger m and a sequence: s[1], s[2], ...... , s[N] in not decreasing order. The length of the sequence is n. Your task is to find out how many pair of a and b satisfy a+b=m. Note that each element of the sequence can use once at most. 

Input

The input consists of multiple test cases. The first line of each test case contains three integers N(0<n<=1000000), M(0<m<=1000000000), which denote the length of the sequence and the sum of a+b, respectively. The next line give n interger(0<s[i]<=10000000)。 Note the input is huge.

Output

For each case, output the num of pairs in one line.

Sample Input

3 3
1 1 2
3 2
1 1 1
5 5
1 1 2 3 4

Sample Output

1
1
2

题意:给定n和m,输入n个数,判断在这些数中有多少组两个数的和为m。
题解:用while跑是最快的,跑n存在风险,跑数组可能超时,跑m一定超时。
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long ll;
ll a[];
int main()
{
ll i,n,m,data;
while(scanf("%lld%lld",&n,&m)!=EOF)
{
memset(a,,sizeof(a));
for(i=;i<n;i++)
scanf("%lld",&a[i]);
ll ans=;
sort(a,a+n);
ll l=,r=n-;
while(l<r)
{
if(a[l]+a[r]>m)
r--;
else if(a[l]+a[r]<m)
l++;
else
{
ans++;
r--;
l++;
}
}
printf("%lld\n",ans);
}
return ;
}

NEFU 2016省赛演练一 I题 (模拟题)的更多相关文章

  1. NEFU 2016省赛演练一 F题 (高精度加法)

    Function1 Problem:F Time Limit:1000ms Memory Limit:65535K Description You know that huicpc0838 has b ...

  2. NEFU 2016省赛演练一 B题(递推)

    HK Problem:B Time Limit:2000ms Memory Limit:65535K Description yy is interested in numbers and yy nu ...

  3. 2019浙大校赛--A--Thanks, TuSimple!(简单模拟题)

    这题前三段都是一堆吹爆赞助商的屁话,正式题目在图片下边,一个简单模拟题. 题目大意: 有n个男生,m个女生在进行舞会,其中一部分男生祥和比自己矮的女生跳舞,一部分男生想和比自己高的女生跳舞,一部分女生 ...

  4. Codeforces Round #237 (Div. 2) B题模拟题

    链接:http://codeforces.com/contest/404/problem/B B. Marathon time limit per test 1 second memory limit ...

  5. HDOJ-6666(简单题+模拟题)

    quailty and ccpc hdoj-6666 题目很简单,按照题目的意思模拟就行了,排序. #include<iostream> #include<cstdio> #i ...

  6. ZOJ1111:Poker Hands(模拟题)

    A poker deck contains 52 cards - each card has a suit which is one of clubs, diamonds, hearts, or sp ...

  7. SCNU ACM 2016新生赛决赛 解题报告

    新生初赛题目.解题思路.参考代码一览 A. 拒绝虐狗 Problem Description CZJ 去排队打饭的时候看到前面有几对情侣秀恩爱,作为单身狗的 CZJ 表示很难受. 现在给出一个字符串代 ...

  8. HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011亚洲北京赛区网络赛)

    HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011 亚洲北京赛区网络赛题目) Eliminate Witches! Time Limit: 2000/1000 ...

  9. 2016湖南省赛----G - Parenthesis (括号匹配)

    2016湖南省赛----G - Parenthesis (括号匹配)   Bobo has a balanced parenthesis sequence P=p 1 p 2…p n of lengt ...

随机推荐

  1. word中打出希腊字母

    作为一个键盘党,不喜欢用鼠标去选择希腊字母,希望只用键盘就能在word中打出希腊字母. 方法是:按照下图所示对应表,先输入英文字母,然后选中它并按Ctrl+Shift+Q

  2. sql注入实例分析

    什么是SQL注入攻击?引用百度百科的解释: sql注入_百度百科: 所谓SQL注入,就是通过把SQL命令插入到Web表单提交或输入域名或页面请求的查询字符串,最终达到欺骗服务器执行恶意的SQL命令.具 ...

  3. footable动态载入数据

    footable_redraw事件 $('#scan').on('click',function(){ var html = '<tr><td>mayidudu</td& ...

  4. tomcat Host及Context 配置

    参考资料: 一.Host配置 对一个Tomcat,可以配置多台虚拟主机.简单地说,就是让一台服务器可以对应多个主机名.这在Tomcat中称之为Host.要求每个Host的Name必须唯一. 配置方法: ...

  5. c/c++细节知识整理

    这篇文章总结了部分c/c++琐碎的细节知识. 目录如下: (一)bool类型 知识点出处较多,无法一一列举,向原作者致敬. (一)bool类型 在c99标准以前,c语言并没有定义bool类型.如果需要 ...

  6. 升级centos6.5系统的gcc为4.8.5的简易步骤

    Centos6.5_64位升级gcc为4.8.2的简易步骤 一.安装依赖包 yum install texinfo-tex flex zip mpfr-devel libgcc.i686 glibc- ...

  7. 实时获取UITextField内容

    在UISearchBar中,当输入信息改变时,它就会调用textDidChange方法, 但是UITextField没有这个功能,要实现就得手动addTarget,其实controlevent里还有很 ...

  8. 自定义NSLog无时间

    #define SXLog(FORMAT, ...) fprintf(stderr,"file --\t%s\nline --\t%d\nmethd --\t%s\noutput --\t\ ...

  9. ios 随机色 宏定义

    #define RGBColor(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1] #d ...

  10. Unity Shader Billboard

    记录来源于ShaderLab开发实战详解 Shader "Tut/Project/Billboard_1" { Properties { _MainTex ("Base ...