这题没名字

Problem:I

Time Limit:2000ms

Memory Limit:65535K

Description

  1. 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

  1. The input consists of multiple test cases. The first line of each test case contains three integers N0<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 interger0<s[i]<=10000000)。 Note the input is huge.

Output

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

Sample Input

  1. 3 3
  2. 1 1 2
  3. 3 2
  4. 1 1 1
  5. 5 5
  6. 1 1 2 3 4

Sample Output

  1. 1
  2. 1
  3. 2

  4. 题意:给定nm,输入n个数,判断在这些数中有多少组两个数的和为m
    题解:用while跑是最快的,跑n存在风险,跑数组可能超时,跑m一定超时。
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <algorithm>
  5. #include <math.h>
  6. using namespace std;
  7. typedef long long ll;
  8. ll a[];
  9. int main()
  10. {
  11. ll i,n,m,data;
  12. while(scanf("%lld%lld",&n,&m)!=EOF)
  13. {
  14. memset(a,,sizeof(a));
  15. for(i=;i<n;i++)
  16. scanf("%lld",&a[i]);
  17. ll ans=;
  18. sort(a,a+n);
  19. ll l=,r=n-;
  20. while(l<r)
  21. {
  22. if(a[l]+a[r]>m)
  23. r--;
  24. else if(a[l]+a[r]<m)
  25. l++;
  26. else
  27. {
  28. ans++;
  29. r--;
  30. l++;
  31. }
  32. }
  33. printf("%lld\n",ans);
  34. }
  35. return ;
  36. }

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. BZOJ-4195 NOI2015Day1T1 程序自动分析 并查集+离散化

    总的来说,这道题水的有点莫名奇妙,不过还好一次轻松A 4195: [Noi2015]程序自动分析 Time Limit: 10 Sec Memory Limit: 512 MB Submit: 836 ...

  2. Hession矩阵与牛顿迭代法

    1.求解方程. 并不是所有的方程都有求根公式,或者求根公式很复杂,导致求解困难.利用牛顿法,可以迭代求解. 原理是利用泰勒公式,在x0处展开,且展开到一阶,即f(x) = f(x0)+(x-x0)f' ...

  3. Rebar:Erlang构建工具

    Rebar是一款Erlang的构建工具,使用它可以方便的编译.测试erlang程序.内联驱动和打包Erlang发行版本. Rebar是一个独立的erlang脚本,所以使用Rebar发布程序非常简单,甚 ...

  4. Spring学习8-Spring事务管理(AOP/声明式式事务管理)

    一.基础知识普及 声明式事务的事务属性: 一:传播行为 二:隔离级别 三:只读提示 四:事务超时间隔 五:异常:指定除去RuntimeException其他回滚异常.  传播行为: 所谓事务的传播行为 ...

  5. [Angularjs]视图和路由(一)

    写在前面 对单页应用来讲,视图和路由的作用可以从一个视图跳转到另外一个视图,可以合理管理用户在使用过程中看到的界面. 将视图分解成布局和模版视图,并且根据用户当前访问的URL来展示对应的视图,将会是一 ...

  6. include ""与include<>

    在C程序中包含文件有以下两种方法:(1)用符号“<”和“>”将要包含的文件的文件名括起来.这种方法指示预处理程序到预定义的缺省路径下寻找文件.预定义的缺省路径通常是在INCLUDE环境变量 ...

  7. Java Web 设置默认首页

    一.问题描述 这里所谓的默认首页,是指在访问项目根目录时(如 http://localhost:8080/zhx-web/ )展示的页面,通过在web.xml里配置 <welcome-file- ...

  8. U盘中的autorun.inf

    怎么删除u盘里的autorun.inf 如果U盘中毒,刚插进机子时按住SHIFT五秒,这样就可以跳过预读,这样防止了预读时把病毒感染到机子上,在U盘盘符上点右键,看看有没有“Auto”选项: 1.如果 ...

  9. XSS Filter Evasion Cheat Sheet 中文版

    前言 译者注: 翻译本文的最初原因是当我自己看到这篇文章后,觉得它是非常有价值.但是这么著名的一个备忘录却一直没有人把它翻译成中文版.很多人仅仅是简单的把文中的 各种代码复制下来,然后看起来很刁的发在 ...

  10. Javascript检测用户注册信息

    <html> <head> <title>用户注册</title> <meta http-equiv="content-type&quo ...